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 |
|---|---|---|---|---|---|---|---|---|---|
Is it possible to get the width of a character when using OpenGL bitmap fonts? | 2,386,849 | <p>I am trying to align my bitmap font text in my OpenGL application but I can't find anything on getting the width of each character. This is my renderText function:</p>
<pre><code>def renderText( self, text, fontFace, position ):
..... (omitted code to make post shorter)
glRasterPos2i( position[0], self.wind... | 1 | 2010-03-05T13:00:52Z | 2,386,885 | <p><a href="http://pyopengl.sourceforge.net/documentation/manual/glutBitmapWidth.3GLUT.xml" rel="nofollow">http://pyopengl.sourceforge.net/documentation/manual/glutBitmapWidth.3GLUT.xml</a></p>
| 1 | 2010-03-05T13:06:46Z | [
"python",
"opengl",
"text",
"fonts",
"width"
] |
"No source for code" message in Coverage.py | 2,386,975 | <p>I ran a build last night, successfully. I got up this morning and ran another without changing any configuration or modifying any source code. Now my build is failing with the message <strong>"No source for code"</strong> when running my <em>nosetests</em> with <em>coverage</em>. </p>
<pre><code>NoSource: No source... | 26 | 2010-03-05T13:21:19Z | 2,401,206 | <p>I'm not sure why it thinks that file exists, but you can tell coverage.py to ignore these problems with a <code>coverage xml -i</code> switch. </p>
<p>If you want to track down the error, drop me a line (ned at ned batchelder com).</p>
| 25 | 2010-03-08T12:25:19Z | [
"python",
"continuous-integration",
"code-coverage",
"nosetests"
] |
"No source for code" message in Coverage.py | 2,386,975 | <p>I ran a build last night, successfully. I got up this morning and ran another without changing any configuration or modifying any source code. Now my build is failing with the message <strong>"No source for code"</strong> when running my <em>nosetests</em> with <em>coverage</em>. </p>
<pre><code>NoSource: No source... | 26 | 2010-03-05T13:21:19Z | 2,402,780 | <p>Ensure theres no .pyc file there, that may have existed in the past.</p>
| 31 | 2010-03-08T16:22:26Z | [
"python",
"continuous-integration",
"code-coverage",
"nosetests"
] |
"No source for code" message in Coverage.py | 2,386,975 | <p>I ran a build last night, successfully. I got up this morning and ran another without changing any configuration or modifying any source code. Now my build is failing with the message <strong>"No source for code"</strong> when running my <em>nosetests</em> with <em>coverage</em>. </p>
<pre><code>NoSource: No source... | 26 | 2010-03-05T13:21:19Z | 3,123,157 | <p><strong>Summary</strong>: Existing .coverage data is kept around when running <code>nosetests --with-coverage</code>, so remove it first.</p>
<p><strong>Details</strong>: I too just encountered this via Hudson and nosetests. This error was coming from <code>coverage/results.py:18</code> (coverage 3.3.1 - there were... | 13 | 2010-06-26T07:57:05Z | [
"python",
"continuous-integration",
"code-coverage",
"nosetests"
] |
"No source for code" message in Coverage.py | 2,386,975 | <p>I ran a build last night, successfully. I got up this morning and ran another without changing any configuration or modifying any source code. Now my build is failing with the message <strong>"No source for code"</strong> when running my <em>nosetests</em> with <em>coverage</em>. </p>
<pre><code>NoSource: No source... | 26 | 2010-03-05T13:21:19Z | 3,312,419 | <p>Maybe this will help, but I ran into a similar error today. And it's a permission error. My code is using a checkout from another user (by design, down ask) and I need to sudo in order for coverage to work. So your issue may have something to it.</p>
| 0 | 2010-07-22T19:05:08Z | [
"python",
"continuous-integration",
"code-coverage",
"nosetests"
] |
"No source for code" message in Coverage.py | 2,386,975 | <p>I ran a build last night, successfully. I got up this morning and ran another without changing any configuration or modifying any source code. Now my build is failing with the message <strong>"No source for code"</strong> when running my <em>nosetests</em> with <em>coverage</em>. </p>
<pre><code>NoSource: No source... | 26 | 2010-03-05T13:21:19Z | 12,693,475 | <p>Just use the '--cover-erase' argument. It fixes this error and you don't have to manually delete coverage files</p>
<pre><code>nosetests --with-coverage --cover-erase
</code></pre>
<p>I'd strongly recommend checking out the help to see what other args you're missing too and don't forget those plugins either</p>
| 8 | 2012-10-02T15:32:20Z | [
"python",
"continuous-integration",
"code-coverage",
"nosetests"
] |
"No source for code" message in Coverage.py | 2,386,975 | <p>I ran a build last night, successfully. I got up this morning and ran another without changing any configuration or modifying any source code. Now my build is failing with the message <strong>"No source for code"</strong> when running my <em>nosetests</em> with <em>coverage</em>. </p>
<pre><code>NoSource: No source... | 26 | 2010-03-05T13:21:19Z | 28,520,829 | <p>The problem is that the <code>.pyc</code> file still exists. </p>
<p>A quick and dirty solution is to delete all <code>.pyc</code> files in that directory:</p>
<pre><code>find . -name "*.pyc" -exec rm -rf {} \;
</code></pre>
| 6 | 2015-02-14T22:04:40Z | [
"python",
"continuous-integration",
"code-coverage",
"nosetests"
] |
"No source for code" message in Coverage.py | 2,386,975 | <p>I ran a build last night, successfully. I got up this morning and ran another without changing any configuration or modifying any source code. Now my build is failing with the message <strong>"No source for code"</strong> when running my <em>nosetests</em> with <em>coverage</em>. </p>
<pre><code>NoSource: No source... | 26 | 2010-03-05T13:21:19Z | 30,489,016 | <p>I ran into this problem as well when trying to run nosetests coverage through setuptools. As mentioned, it is possible to delete existing .pyc files but that can be cumbersome.</p>
<p>I ended up having to create a .coveragerc file with the following</p>
<blockquote>
<p>[report]</p>
<p>ignore_errors = True</... | 0 | 2015-05-27T17:10:45Z | [
"python",
"continuous-integration",
"code-coverage",
"nosetests"
] |
Re-order list in Python to ensure it starts with check values | 2,387,068 | <p>I'm reading in serial data using Pyserial, to populate a list of 17 values (1byte each) at a sampling rate of 256Hz.</p>
<p>The bytes I ultimately want to use are the 5th to 8th in the list. Providing no bytes are dropped, the first two values of the stream are always the same ('165','90'). I'm getting quite a few... | 5 | 2010-03-05T13:39:32Z | 2,387,184 | <p>In case I understood you well,
suppose you have a list like this:</p>
<pre><code>l = [67, 126, 165, 90, 11, 1, 3, 5, 151, 99, 23]
</code></pre>
<p>you'd want to obtain:
useful = [3,5,151,99]</p>
<p>Then, you could do:</p>
<pre><code># obtain places where 165 is followed by 90
match = [x for x in xrange(len(l... | 2 | 2010-03-05T14:00:44Z | [
"python",
"list"
] |
Re-order list in Python to ensure it starts with check values | 2,387,068 | <p>I'm reading in serial data using Pyserial, to populate a list of 17 values (1byte each) at a sampling rate of 256Hz.</p>
<p>The bytes I ultimately want to use are the 5th to 8th in the list. Providing no bytes are dropped, the first two values of the stream are always the same ('165','90'). I'm getting quite a few... | 5 | 2010-03-05T13:39:32Z | 2,387,355 | <p>If I understand your problem correct, you have data continuously arriving, in 17-byte chunks. Assuming that's right, how about something like this:</p>
<pre><code>while True:
mylist.extend(get_more_data())
# If we're misaligned, skip bytes until we're aligned again
while mylist and mylist[0] != 16... | 0 | 2010-03-05T14:26:45Z | [
"python",
"list"
] |
Re-order list in Python to ensure it starts with check values | 2,387,068 | <p>I'm reading in serial data using Pyserial, to populate a list of 17 values (1byte each) at a sampling rate of 256Hz.</p>
<p>The bytes I ultimately want to use are the 5th to 8th in the list. Providing no bytes are dropped, the first two values of the stream are always the same ('165','90'). I'm getting quite a few... | 5 | 2010-03-05T13:39:32Z | 2,397,371 | <p>I would use the 165 and 90 as header values, always checking the incoming byte for a match. This solution automatically re-syncs itself and it is as simple as:</p>
<pre><code>def get_message():
while True: #Some timeout functionality is useful here ;-)
message = []
byte = xxx.get_byte()
if ... | 0 | 2010-03-07T18:30:05Z | [
"python",
"list"
] |
Calculating difference within lists | 2,387,126 | <p>I have two files and the content is as follows:</p>
<p><img src="http://img144.imageshack.us/img144/4423/screencapture2b.png" alt="alt text"></p>
<p><img src="http://img229.imageshack.us/img229/9153/screencapture1c.png" alt="alt text"></p>
<p>Please only consider the bolded column and the red column. The remainin... | 1 | 2010-03-05T13:50:17Z | 2,387,212 | <p>I haven't understood your problem fully but </p>
<p>File 1</p>
<pre><code>100 C 20.2
300 B 33.3
</code></pre>
<p>File 2</p>
<pre><code>110 C 20.23
320 B 33.34
</code></pre>
<p>and you want to compare 3rd column of the two files.</p>
<pre><code>lines1 = file1.readlines()
list1 = [float(line.split()[2]) for line... | 0 | 2010-03-05T14:05:17Z | [
"python",
"list"
] |
Calculating difference within lists | 2,387,126 | <p>I have two files and the content is as follows:</p>
<p><img src="http://img144.imageshack.us/img144/4423/screencapture2b.png" alt="alt text"></p>
<p><img src="http://img229.imageshack.us/img229/9153/screencapture1c.png" alt="alt text"></p>
<p>Please only consider the bolded column and the red column. The remainin... | 1 | 2010-03-05T13:50:17Z | 2,387,435 | <p>The direct answer to your question is to alter the last condition, <br>
<code>if y[35:38] !=x[35:38]:</code>
so that instead the "field" at [35:38] get converted to int (or float...) and a difference can be applied to them. Giving something like</p>
<pre><code> try:
iy = int(y[35:38])
ix = int(x[35:3... | 2 | 2010-03-05T14:35:29Z | [
"python",
"list"
] |
Calculating difference within lists | 2,387,126 | <p>I have two files and the content is as follows:</p>
<p><img src="http://img144.imageshack.us/img144/4423/screencapture2b.png" alt="alt text"></p>
<p><img src="http://img229.imageshack.us/img229/9153/screencapture1c.png" alt="alt text"></p>
<p>Please only consider the bolded column and the red column. The remainin... | 1 | 2010-03-05T13:50:17Z | 2,387,468 | <p>Nothing to do with your problem, but this:</p>
<pre><code> if y[11]=="C":
if y[35:38]!= "EN":
# I don't see any "EN" or "OTE" anywhere in your sample input.
# In any case the above condition will always be true, because
# y[35:38] appears to be a 3-byte string but "EN" is a 2-byte string.
... | 2 | 2010-03-05T14:39:19Z | [
"python",
"list"
] |
Open Source FIX Client Simulator | 2,387,173 | <p>I want test a FIX gateway for our company and was wondering if anything in opensource already exists that I can use or perhaps leverage to complete this task. </p>
<p>I am currently looking at QuickFix but I am not sure if it has a client that can be use against any standard FIX gateway. </p>
<p>Also links to any ... | 8 | 2010-03-05T13:58:35Z | 2,413,039 | <p>QuickFIX can be used to send standard-compliant messages (with different safety-levels//use strong safety:-) to FIX servers/gateways.</p>
<p>quickfix has nice sample code on its site: <a href="http://www.quickfixengine.org/quickfix/doc/html/sending_messages.html" rel="nofollow">http://www.quickfixengine.org/quickfi... | 2 | 2010-03-09T22:22:41Z | [
"c++",
"python",
"quickfix",
"fix"
] |
Open Source FIX Client Simulator | 2,387,173 | <p>I want test a FIX gateway for our company and was wondering if anything in opensource already exists that I can use or perhaps leverage to complete this task. </p>
<p>I am currently looking at QuickFix but I am not sure if it has a client that can be use against any standard FIX gateway. </p>
<p>Also links to any ... | 8 | 2010-03-05T13:58:35Z | 2,421,178 | <p><strong>QuickFIXengine code comes with couple of examples, see <a href="http://www.quickfixengine.org/quickfix/doc/html/examples.html">http://www.quickfixengine.org/quickfix/doc/html/examples.html</a></strong></p>
<p>You probably want <code>tradeclient</code> for sending messages. It is a command line tool that wil... | 11 | 2010-03-10T22:35:14Z | [
"c++",
"python",
"quickfix",
"fix"
] |
Django: Manually getting the view corresponding to a URL | 2,387,427 | <p>I have a Django project. Given a url, how can I know which view will be dispatched to handle the request?</p>
| 4 | 2010-03-05T14:34:22Z | 2,387,476 | <p>You want <code>django.core.urlresolvers.resolve</code>, which allows you to map an URL to a view and to keep your URL & view logic separate. This is the opposite of <code>django.core.urlresolvers.reverse</code> which allows you to map a view to a URL.</p>
<p>See the <a href="http://docs.djangoproject.com/en/de... | 6 | 2010-03-05T14:39:52Z | [
"python",
"django",
"url"
] |
What is the most pythonic way to extend a list with the reversal of another? | 2,387,558 | <p>I have one list that I want to take a slice of, reverse that slice and append each of those items onto the end of another list. The following are the options I have thought of (although if you have others please share), which of these is the most pythonic?</p>
<pre><code># Option 1
tmp = color[-bits:]
tmp.reverse(... | 1 | 2010-03-05T14:52:44Z | 2,387,576 | <pre><code>my_list.extend(color[:-(bits + 1):-1])
</code></pre>
| 0 | 2010-03-05T14:56:02Z | [
"list",
"python",
"reverse"
] |
What is the most pythonic way to extend a list with the reversal of another? | 2,387,558 | <p>I have one list that I want to take a slice of, reverse that slice and append each of those items onto the end of another list. The following are the options I have thought of (although if you have others please share), which of these is the most pythonic?</p>
<pre><code># Option 1
tmp = color[-bits:]
tmp.reverse(... | 1 | 2010-03-05T14:52:44Z | 2,387,618 | <p>For Option #2, you can cut out the call to <code>list</code>. You could also use <code>+=</code> instead of <code>extend</code>, like so:</p>
<pre><code>my_list += reversed(color[-bits:])
</code></pre>
| 0 | 2010-03-05T15:01:05Z | [
"list",
"python",
"reverse"
] |
What is the most pythonic way to extend a list with the reversal of another? | 2,387,558 | <p>I have one list that I want to take a slice of, reverse that slice and append each of those items onto the end of another list. The following are the options I have thought of (although if you have others please share), which of these is the most pythonic?</p>
<pre><code># Option 1
tmp = color[-bits:]
tmp.reverse(... | 1 | 2010-03-05T14:52:44Z | 2,387,701 | <p>I like</p>
<pre><code>my_list.extend(reversed(color[-bits:]))
</code></pre>
<p>It explains what you are doing ( extending a list by reverse of another list's slice) and is short too.</p>
<p>and a obligatory itertools solution</p>
<pre><code>my_list.extend( itertools.islice( reversed(color), 0, bits))
</code></pr... | 3 | 2010-03-05T15:12:01Z | [
"list",
"python",
"reverse"
] |
Batch Paypal Payments | 2,387,591 | <p>Can you send a paypal payment with a script? I've been googling for this, but I can't seem to find the answer I want (yes) ;-)</p>
<p>An example of what I am talking about: Lets say I have a site where users share in the profit. Instead of sending each users payment out manually at the end of the month, I would ... | 6 | 2010-03-05T14:58:18Z | 2,387,660 | <p>Yes. This page may help:
<a href="https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_api_masspay" rel="nofollow">https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_api_masspay</a></p>
<p>Clarification edit:
Basically you use the mass-pay API cal... | 2 | 2010-03-05T15:07:12Z | [
"python",
"django",
"paypal"
] |
Batch Paypal Payments | 2,387,591 | <p>Can you send a paypal payment with a script? I've been googling for this, but I can't seem to find the answer I want (yes) ;-)</p>
<p>An example of what I am talking about: Lets say I have a site where users share in the profit. Instead of sending each users payment out manually at the end of the month, I would ... | 6 | 2010-03-05T14:58:18Z | 2,387,664 | <p>You might want to check out the <a href="https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_api_reference" rel="nofollow">Paypal API documentation</a></p>
| 2 | 2010-03-05T15:07:28Z | [
"python",
"django",
"paypal"
] |
Best way to convert csv data to dict | 2,387,697 | <p>I have csv file with following data</p>
<pre><code>val1,val2,val3
1,2,3
22,23,33
</code></pre>
<p>So how can I convert data into dict</p>
<pre><code>dict1 = { 'val1': 1, 'val2': 2, 'val3': 3}
dict2 = { 'val1': 22, 'val2': 23, 'val3': 33}
fp = open('file.csv', 'r')
reader = csv.reader(fp)
for row in reader:
??... | 11 | 2010-03-05T15:11:29Z | 2,387,748 | <p>Use <a href="http://docs.python.org/library/csv.html#csv.DictReader" rel="nofollow">csv.DictReader</a>:</p>
<blockquote>
<p>Create an object which operates like a regular reader but maps the information read into a dict whose keys are given by the optional <em>fieldnames</em> parameter. The <em>fieldnames</em> pa... | 11 | 2010-03-05T15:18:26Z | [
"python",
"csv"
] |
Best way to convert csv data to dict | 2,387,697 | <p>I have csv file with following data</p>
<pre><code>val1,val2,val3
1,2,3
22,23,33
</code></pre>
<p>So how can I convert data into dict</p>
<pre><code>dict1 = { 'val1': 1, 'val2': 2, 'val3': 3}
dict2 = { 'val1': 22, 'val2': 23, 'val3': 33}
fp = open('file.csv', 'r')
reader = csv.reader(fp)
for row in reader:
??... | 11 | 2010-03-05T15:11:29Z | 2,387,754 | <pre><code>import csv
reader = csv.DictReader(open('myfile.csv'))
for row in reader:
# profit !
</code></pre>
| 17 | 2010-03-05T15:18:59Z | [
"python",
"csv"
] |
Use subprocess to send a password | 2,387,731 | <p>I'm attempting to use the python subprocess module to log in to a secure ftp site and then grab a file. However I keep getting hung up on just trying to send the password when it is requested. I so far have the following code:</p>
<pre><code>from subprocess import Popen, PIPE
proc = Popen(['sftp','user@server', 's... | 10 | 2010-03-05T15:16:27Z | 2,387,776 | <p>Try</p>
<pre><code>proc.stdin.write('yourPassword\n')
proc.stdin.flush()
</code></pre>
<p>That should work.</p>
<p>What you describe sounds like <code>stdin=None</code> where the child process inherits the stdin of the parent (your Python program).</p>
| 4 | 2010-03-05T15:22:38Z | [
"python",
"subprocess",
"sftp"
] |
Use subprocess to send a password | 2,387,731 | <p>I'm attempting to use the python subprocess module to log in to a secure ftp site and then grab a file. However I keep getting hung up on just trying to send the password when it is requested. I so far have the following code:</p>
<pre><code>from subprocess import Popen, PIPE
proc = Popen(['sftp','user@server', 's... | 10 | 2010-03-05T15:16:27Z | 2,387,842 | <p>Perhaps you should use an <a href="http://linux.die.net/man/1/expect">expect</a>-like library instead?</p>
<p>For instance <a href="http://www.noah.org/wiki/Pexpect">Pexpect</a> (<a href="http://www.noah.org/wiki/Pexpect#Overview">example</a>). There are other, similar python libraries as well.</p>
| 5 | 2010-03-05T15:29:52Z | [
"python",
"subprocess",
"sftp"
] |
Use subprocess to send a password | 2,387,731 | <p>I'm attempting to use the python subprocess module to log in to a secure ftp site and then grab a file. However I keep getting hung up on just trying to send the password when it is requested. I so far have the following code:</p>
<pre><code>from subprocess import Popen, PIPE
proc = Popen(['sftp','user@server', 's... | 10 | 2010-03-05T15:16:27Z | 2,389,105 | <p>I would recommend scrapping the subprocess approach and using the paramiko package for sftp access.</p>
| 1 | 2010-03-05T18:42:48Z | [
"python",
"subprocess",
"sftp"
] |
Python - Can I access the object who call me? | 2,387,756 | <p>If I have this:</p>
<pre><code>class A:
def callFunction(self, obj):
obj.otherFunction()
class B:
def callFunction(self, obj):
obj.otherFunction()
class C:
def otherFunction(self):
# here I wan't to have acces to the instance of A or B who call me.
...
# in main or other obje... | 3 | 2010-03-05T15:19:27Z | 2,387,800 | <p>Examine the stack with the <a href="http://docs.python.org/library/inspect.html#the-interpreter-stack" rel="nofollow">inspect module</a> with <code>inspect.stack()</code>. You can then get the instance from each element in the list with <code>f_locals['self']</code></p>
| 1 | 2010-03-05T15:25:06Z | [
"python",
"oop",
"function-calls"
] |
Python - Can I access the object who call me? | 2,387,756 | <p>If I have this:</p>
<pre><code>class A:
def callFunction(self, obj):
obj.otherFunction()
class B:
def callFunction(self, obj):
obj.otherFunction()
class C:
def otherFunction(self):
# here I wan't to have acces to the instance of A or B who call me.
...
# in main or other obje... | 3 | 2010-03-05T15:19:27Z | 2,387,854 | <p>Here is a quick hack, get the stack and from last frame get locals to access self</p>
<pre><code>class A:
def callFunction(self, obj):
obj.otherFunction()
class B:
def callFunction(self, obj):
obj.otherFunction()
import inspect
class C:
def otherFunction(self):
lastFrame = ins... | 3 | 2010-03-05T15:32:19Z | [
"python",
"oop",
"function-calls"
] |
Python - Can I access the object who call me? | 2,387,756 | <p>If I have this:</p>
<pre><code>class A:
def callFunction(self, obj):
obj.otherFunction()
class B:
def callFunction(self, obj):
obj.otherFunction()
class C:
def otherFunction(self):
# here I wan't to have acces to the instance of A or B who call me.
...
# in main or other obje... | 3 | 2010-03-05T15:19:27Z | 2,387,857 | <p>If this is for debugging purposes you can use inspect.currentframe():</p>
<pre><code>import inspect
class C:
def otherFunction(self):
print inspect.currentframe().f_back.f_locals
</code></pre>
<p>Here is the output:</p>
<pre><code>>>> A().callFunction(C())
{'self': <__main__.A instance at... | 10 | 2010-03-05T15:32:48Z | [
"python",
"oop",
"function-calls"
] |
Error setting up thrift modules for python | 2,387,816 | <p>I'm trying to set up <a href="http://incubator.apache.org/thrift/" rel="nofollow">thrift</a> in order to incorporate with <a href="http://incubator.apache.org/cassandra/" rel="nofollow">Cassandra</a>, so when I ran the</p>
<pre><code>setup.py
</code></pre>
<p>it out puts this message in command line</p>
<pre><cod... | 1 | 2010-03-05T15:26:39Z | 2,438,325 | <p>I've only succeeded in installing Thrift with MSVC.</p>
<ul>
<li>Install MSVC</li>
<li>Get Thrift</li>
<li>Apply thrift-252-python-msvc-1.diff patch (google it)</li>
</ul>
<p>The fastbinary.c will be patched, but setup.py patch will fail, update manually from hints at setup.py.rej, here's a (seemingly) correct cop... | 0 | 2010-03-13T12:36:47Z | [
"python",
"thrift"
] |
Error setting up thrift modules for python | 2,387,816 | <p>I'm trying to set up <a href="http://incubator.apache.org/thrift/" rel="nofollow">thrift</a> in order to incorporate with <a href="http://incubator.apache.org/cassandra/" rel="nofollow">Cassandra</a>, so when I ran the</p>
<pre><code>setup.py
</code></pre>
<p>it out puts this message in command line</p>
<pre><cod... | 1 | 2010-03-05T15:26:39Z | 4,565,242 | <p>Install python-dev</p>
<p>You can run:
sudo apt-get install python-dev </p>
| 0 | 2010-12-30T18:35:06Z | [
"python",
"thrift"
] |
Error setting up thrift modules for python | 2,387,816 | <p>I'm trying to set up <a href="http://incubator.apache.org/thrift/" rel="nofollow">thrift</a> in order to incorporate with <a href="http://incubator.apache.org/cassandra/" rel="nofollow">Cassandra</a>, so when I ran the</p>
<pre><code>setup.py
</code></pre>
<p>it out puts this message in command line</p>
<pre><cod... | 1 | 2010-03-05T15:26:39Z | 23,423,592 | <p>With a bit of source file tweaking it is possible to install it with MINGW on Windows. I'm using thrift 0.9.1 and Python 27 </p>
<p>The steps I followed were: </p>
<ol>
<li><p>If you are using Python 2.7, follow the normal setup steps and workarounds for minGW. In particular you may need to open the file C:\Python... | 1 | 2014-05-02T08:11:54Z | [
"python",
"thrift"
] |
Pythonic way to compare two lists and print out the differences | 2,387,981 | <p>I have two lists which are guaranteed to be the same length. I want to compare the corresponding values in the list (except the first item) and print out the ones which dont match. The way I am doing it is like this</p>
<pre><code>i = len(list1)
if i == 1:
print 'Nothing to compare'
else:
for i in range(i):... | 13 | 2010-03-05T15:50:13Z | 2,388,002 | <p>edit: oops, didn't see the "ignore first item" part</p>
<pre><code>from itertools import islice,izip
for a,b in islice(izip(list1,list2),1,None):
if a != b:
print a, b
</code></pre>
| 2 | 2010-03-05T15:52:10Z | [
"python",
"comparison"
] |
Pythonic way to compare two lists and print out the differences | 2,387,981 | <p>I have two lists which are guaranteed to be the same length. I want to compare the corresponding values in the list (except the first item) and print out the ones which dont match. The way I am doing it is like this</p>
<pre><code>i = len(list1)
if i == 1:
print 'Nothing to compare'
else:
for i in range(i):... | 13 | 2010-03-05T15:50:13Z | 2,388,016 | <p>There's a nice class called <code>difflib.SequenceMatcher</code> in the standard library for that.</p>
| 2 | 2010-03-05T15:54:57Z | [
"python",
"comparison"
] |
Pythonic way to compare two lists and print out the differences | 2,387,981 | <p>I have two lists which are guaranteed to be the same length. I want to compare the corresponding values in the list (except the first item) and print out the ones which dont match. The way I am doing it is like this</p>
<pre><code>i = len(list1)
if i == 1:
print 'Nothing to compare'
else:
for i in range(i):... | 13 | 2010-03-05T15:50:13Z | 2,388,064 | <pre><code>list1=[1,2,3,4]
list2=[1,5,3,4]
print [(i,j) for i,j in zip(list1,list2) if i!=j]
</code></pre>
<p>Output:</p>
<pre><code>[(2, 5)]
</code></pre>
<p><strong>Edit:</strong> Easily extended to skip <em>n</em> first items (same output):</p>
<pre><code>list1=[1,2,3,4]
list2=[2,5,3,4]
print [(i,j) for i,j in z... | 18 | 2010-03-05T16:01:08Z | [
"python",
"comparison"
] |
Pythonic way to compare two lists and print out the differences | 2,387,981 | <p>I have two lists which are guaranteed to be the same length. I want to compare the corresponding values in the list (except the first item) and print out the ones which dont match. The way I am doing it is like this</p>
<pre><code>i = len(list1)
if i == 1:
print 'Nothing to compare'
else:
for i in range(i):... | 13 | 2010-03-05T15:50:13Z | 2,388,227 | <p>Noting the requirement to skip the first line:</p>
<pre><code>from itertools import izip
both = izip(list1,list2)
both.next() #skip the first
for p in (p for p in both if p[0]!=p[1]):
print pair
</code></pre>
<ol><li>This uses <a href="http://docs.python.org/library/itertools.html#itertools.izip" rel="nofollow... | 2 | 2010-03-05T16:23:49Z | [
"python",
"comparison"
] |
Pythonic way to compare two lists and print out the differences | 2,387,981 | <p>I have two lists which are guaranteed to be the same length. I want to compare the corresponding values in the list (except the first item) and print out the ones which dont match. The way I am doing it is like this</p>
<pre><code>i = len(list1)
if i == 1:
print 'Nothing to compare'
else:
for i in range(i):... | 13 | 2010-03-05T15:50:13Z | 2,388,340 | <p>Nobody's mentioned filter:</p>
<pre><code>a = [1, 2, 3]
b = [42, 3, 4]
aToCompare = a[1:]
bToCompare = b[1:]
c = filter( lambda x: (not(x in aToCompare)), bToCompare)
print c
</code></pre>
| 4 | 2010-03-05T16:41:16Z | [
"python",
"comparison"
] |
Pythonic way to compare two lists and print out the differences | 2,387,981 | <p>I have two lists which are guaranteed to be the same length. I want to compare the corresponding values in the list (except the first item) and print out the ones which dont match. The way I am doing it is like this</p>
<pre><code>i = len(list1)
if i == 1:
print 'Nothing to compare'
else:
for i in range(i):... | 13 | 2010-03-05T15:50:13Z | 2,389,868 | <p>You could use sets:</p>
<pre><code>>>> list1=[1,2,3,4]
>>> list2=[1,5,3,4]
>>> set(list1[1:]).symmetric_difference(list2[1:])
set([2, 5])
</code></pre>
| 2 | 2010-03-05T20:57:07Z | [
"python",
"comparison"
] |
Pythonic way to compare two lists and print out the differences | 2,387,981 | <p>I have two lists which are guaranteed to be the same length. I want to compare the corresponding values in the list (except the first item) and print out the ones which dont match. The way I am doing it is like this</p>
<pre><code>i = len(list1)
if i == 1:
print 'Nothing to compare'
else:
for i in range(i):... | 13 | 2010-03-05T15:50:13Z | 18,063,239 | <p>Assuming the two types are equal and have the same length:</p>
<pre><code>list1=[1,2,3,4]
list2=[1,5,3,4]
print list1==list2
</code></pre>
| 0 | 2013-08-05T16:35:56Z | [
"python",
"comparison"
] |
Can you help me solve this SUDS/SOAP issue? | 2,388,046 | <p>So I'm trying to access this api <a href="https://www.clarityaccounting.com/api-docs/">https://www.clarityaccounting.com/api-docs/</a> using SUDS. Here is the code that should work:</p>
<pre><code>from suds.client import Client
client = Client('https://www.clarityaccounting.com/api/v1?wsdl')
token = client.service... | 15 | 2010-03-05T15:58:37Z | 2,388,590 | <p>At first glance looks like the problem you're having is with SSL. You are accessing an https URL, and the Transport handler for suds.client talks http by default. </p>
<p><strong>The problem</strong><br>
If you look at the bottom of the WSDL it is specifying the default location as <code>http://www.clarityaccounti... | 32 | 2010-03-05T17:19:10Z | [
"python",
"soap",
"wsdl",
"suds"
] |
Can you help me solve this SUDS/SOAP issue? | 2,388,046 | <p>So I'm trying to access this api <a href="https://www.clarityaccounting.com/api-docs/">https://www.clarityaccounting.com/api-docs/</a> using SUDS. Here is the code that should work:</p>
<pre><code>from suds.client import Client
client = Client('https://www.clarityaccounting.com/api/v1?wsdl')
token = client.service... | 15 | 2010-03-05T15:58:37Z | 2,389,776 | <p>It shouldn't be a problem related to connecting to a service over HTTPS. I'm using suds to do the same thing. I've tried a few approaches to your WSDL file (not an expert myself) and encountered the same error. What you should do as practice with suds though is use the <strong>factory</strong> method, e.g. </p>
<pr... | 1 | 2010-03-05T20:36:30Z | [
"python",
"soap",
"wsdl",
"suds"
] |
Can you help me solve this SUDS/SOAP issue? | 2,388,046 | <p>So I'm trying to access this api <a href="https://www.clarityaccounting.com/api-docs/">https://www.clarityaccounting.com/api-docs/</a> using SUDS. Here is the code that should work:</p>
<pre><code>from suds.client import Client
client = Client('https://www.clarityaccounting.com/api/v1?wsdl')
token = client.service... | 15 | 2010-03-05T15:58:37Z | 26,650,004 | <p>Using suds-jurko <a href="https://pypi.python.org/pypi/suds-jurko" rel="nofollow">https://pypi.python.org/pypi/suds-jurko</a> which is a maintained fork of suds.
You can pass in an __inject option where you can give it the raw xml you want to send.</p>
<pre><code>from suds.client import Client
username, password, ... | 1 | 2014-10-30T10:00:26Z | [
"python",
"soap",
"wsdl",
"suds"
] |
unbound python method, potentially scope issue | 2,388,359 | <p>I'm using iPython right now to interactively set up a Twisted network. The script that I run in iPython describes best of what I have to do:</p>
<pre><code>import router, pdb
# creates nodes which encapsulate RandomVector and VectorAdder objects
a = router.LocalNode(router.RandomVector, '/topic/a_c')
b = router.Lo... | 0 | 2010-03-05T16:45:06Z | 2,388,537 | <p>I don't think this is a scoping issue. Are you sure you don't need to use:</p>
<pre><code>a = router.LocalNode(router.RandomVector(), '/topic/a_c')
b = router.LocalNode(router.RandomVector(), '/topic/b_c')
</code></pre>
<p>i.e. instantiate the RandomVector you pass to LocalNode?</p>
<p>This recommendation is trig... | 2 | 2010-03-05T17:10:54Z | [
"python",
"twisted"
] |
Python: better file I/0 using os.fork? | 2,388,394 | <p>My problem is quite simple: I have a 400MB file filled with 10,000,000 lines of data. I need to iterate over each line, do something, and remove the line from memory to avoid filling-up too much RAM.</p>
<p>Since my machine has several processor, my initial idea to optimize this process was to create two different ... | 3 | 2010-03-05T16:49:08Z | 2,388,416 | <p>You're probably limited by the speed of your disk. Python already does buffering so reading it line by line is efficient.</p>
| 2 | 2010-03-05T16:51:28Z | [
"python",
"file-io",
"multiprocessing",
"shared-memory"
] |
Python: better file I/0 using os.fork? | 2,388,394 | <p>My problem is quite simple: I have a 400MB file filled with 10,000,000 lines of data. I need to iterate over each line, do something, and remove the line from memory to avoid filling-up too much RAM.</p>
<p>Since my machine has several processor, my initial idea to optimize this process was to create two different ... | 3 | 2010-03-05T16:49:08Z | 2,388,418 | <p>Your proposed <code>for line in open('/data/workfile', 'r'):</code> will use a generator, so the entire file will not be read into memory. I'd go with that until it actually turns out to be too slow.</p>
| 4 | 2010-03-05T16:52:04Z | [
"python",
"file-io",
"multiprocessing",
"shared-memory"
] |
Python: better file I/0 using os.fork? | 2,388,394 | <p>My problem is quite simple: I have a 400MB file filled with 10,000,000 lines of data. I need to iterate over each line, do something, and remove the line from memory to avoid filling-up too much RAM.</p>
<p>Since my machine has several processor, my initial idea to optimize this process was to create two different ... | 3 | 2010-03-05T16:49:08Z | 2,388,684 | <p>The data structure you want to use is a Queue (it has the proper blocking mechanisms by example for concurrent writes), that is available in Multiprocessing module.</p>
<p>If you have no dependency between the processing of your data, you could MAP the line by line generator to a pool of processes with the function... | 0 | 2010-03-05T17:34:01Z | [
"python",
"file-io",
"multiprocessing",
"shared-memory"
] |
Python: better file I/0 using os.fork? | 2,388,394 | <p>My problem is quite simple: I have a 400MB file filled with 10,000,000 lines of data. I need to iterate over each line, do something, and remove the line from memory to avoid filling-up too much RAM.</p>
<p>Since my machine has several processor, my initial idea to optimize this process was to create two different ... | 3 | 2010-03-05T16:49:08Z | 5,685,274 | <p>Probably before blind optimizing would be better to profile your existing code and see where the bottle neck really is. </p>
<p>Even if processing really is I/O bound adding couple threads to program could help a bit.</p>
<p>This will allow another thread to wait IO while another is processing the previously read ... | 1 | 2011-04-16T08:09:22Z | [
"python",
"file-io",
"multiprocessing",
"shared-memory"
] |
telnetlib TypeError | 2,388,414 | <p>I am modifying a python script to make changes en masse to a hand full of switches via telnet:</p>
<pre><code>import getpass
import sys
import telnetlib
HOST = "192.168.1.1"
user = input("Enter your remote account: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
tn.read_until("User Name: ")
tn.write(... | 0 | 2010-03-05T16:51:28Z | 2,391,597 | <p>Per <a href="http://docs.python.org/3.1/library/telnetlib.html?highlight=telnetlib#telnetlib.Telnet.read_until" rel="nofollow">the docs</a>, <code>read_until</code>'s specs are (quoting, my emphasis):</p>
<blockquote>
<p>Read until a given <strong>byte</strong> string,
expected, is encountered</p>
</blockquote>... | 2 | 2010-03-06T06:30:43Z | [
"python",
"python-3.x",
"telnet"
] |
Calling Java app with "subprocess" from Python and reading the Java app output | 2,388,423 | <p>What is the nicest way to read the output (i.e. via System.out.println) of a Java app which is called from Python with </p>
<pre><code>subprocess.Popen("java MyClass", shell=True)
</code></pre>
<p>without writing and reading a file? (Using Jython etc is not a possible solution)</p>
| 3 | 2010-03-05T16:52:37Z | 2,388,447 | <pre><code>p1 = subprocess.Popen(["/usr/bin/java", "MyClass"], stdout=subprocess.PIPE)
print p1.stdout.read()
</code></pre>
| 4 | 2010-03-05T16:56:15Z | [
"java",
"python",
"communication"
] |
Calling Java app with "subprocess" from Python and reading the Java app output | 2,388,423 | <p>What is the nicest way to read the output (i.e. via System.out.println) of a Java app which is called from Python with </p>
<pre><code>subprocess.Popen("java MyClass", shell=True)
</code></pre>
<p>without writing and reading a file? (Using Jython etc is not a possible solution)</p>
| 3 | 2010-03-05T16:52:37Z | 2,388,469 | <p>I just found the solution:</p>
<pre><code>p = subprocess.Popen("java MyClass",
shell=True,
stdout=subprocess.PIPE)
output, errors = p.communicate()
</code></pre>
<p>S.Mark's is fine too!</p>
| 2 | 2010-03-05T16:59:47Z | [
"java",
"python",
"communication"
] |
Figuring out duration of an event in Python | 2,388,486 | <p>This is a very noobish question, so I apologize in advance!</p>
<p>I have two time stamps for start and end of the event. They are stored in as datetime.datetime in UTC. What I need to do is figure out the duration of the event.</p>
<p>I tried subtracting one from the other, but receive error:</p>
<pre>
Traceback... | 2 | 2010-03-05T17:01:30Z | 2,388,519 | <p>Subtracting one <a href="http://docs.python.org/library/datetime.html#datetime-objects"><code>datetime</code></a> from another will give you a <a href="http://docs.python.org/library/datetime.html#timedelta-objects"><code>timedelta</code></a>. You can use that to create another <code>datetime</code> if you need to ... | 5 | 2010-03-05T17:07:16Z | [
"python",
"google-app-engine"
] |
Figuring out duration of an event in Python | 2,388,486 | <p>This is a very noobish question, so I apologize in advance!</p>
<p>I have two time stamps for start and end of the event. They are stored in as datetime.datetime in UTC. What I need to do is figure out the duration of the event.</p>
<p>I tried subtracting one from the other, but receive error:</p>
<pre>
Traceback... | 2 | 2010-03-05T17:01:30Z | 2,388,727 | <p>The difference of two <code>datetime.datetime</code> objects is a <code>datetime.timedelta</code> object:</p>
<pre><code>In [2]: t1=datetime.datetime.now()
In [3]: t1
Out[3]: datetime.datetime(2010, 3, 5, 12, 34, 6, 402507)
In [4]: t2=datetime.datetime.now()
In [5]: dt=t2-t1
In [6]: dt
Out[6]: datetime.timedelt... | 1 | 2010-03-05T17:39:13Z | [
"python",
"google-app-engine"
] |
Figuring out duration of an event in Python | 2,388,486 | <p>This is a very noobish question, so I apologize in advance!</p>
<p>I have two time stamps for start and end of the event. They are stored in as datetime.datetime in UTC. What I need to do is figure out the duration of the event.</p>
<p>I tried subtracting one from the other, but receive error:</p>
<pre>
Traceback... | 2 | 2010-03-05T17:01:30Z | 2,392,566 | <p>For stuff like this I always use time.time() that gives back a nice float and then mostly format it something like this:</p>
<pre><code>import time
t1 = time.time()
someLongTakingFunction()
print "Function took %.2f" % (time.time() - t1)
</code></pre>
<p>This is nice for quick and dirty checks, but supposedly t... | 0 | 2010-03-06T13:18:28Z | [
"python",
"google-app-engine"
] |
How to get the contents of a field instead of `<bound method...` in a CSV output with Python (pytwist) | 2,389,025 | <p>The snippet below is generating "weird" output:</p>
<pre><code>for s in servers:
vo = ss.getServerVO(s)
values = []
for f in voFields:
attribValue = getattr(vo, f)
values.append(attribValue)
customValues = ss.getCustomFields(s)
for f in customFields:
values.append(customV... | 1 | 2010-03-05T18:28:52Z | 2,389,101 | <p>You could try calling the bound method if it is one:</p>
<pre><code>for f, v in customFields.iteritems():
try:
v = v()
except TypeError:
pass
values.append(v)
</code></pre>
<p>The problem, of course, is with the design choice (by HP or whoever) to mix "accessors" with other kinds of values -- accesso... | 1 | 2010-03-05T18:42:07Z | [
"python",
"csv",
"hpsa"
] |
Python list entries are overridden by last appended entry | 2,389,094 | <p>I've got this code:</p>
<pre><code>def __parse(self):
for line in self.lines:
r = Record(line)
self.records[len(self.records):] = [r]
print self.records[len(self.records)-1].getValue() # Works fine!
print self.record[0].getValue() # Gives the same as
print self.record[1].... | 0 | 2010-03-05T18:40:44Z | 2,389,118 | <p>You aren't appending to <code>self.records</code>; you are always overwriting it.</p>
<p>Use:</p>
<p><code>self.records.append(r)</code> </p>
<p>instead.</p>
<p><strong>Edit</strong>: Never mind. See Ignacio Vasquez-Abrams's comment. I would delete this answer if not for that.</p>
| 1 | 2010-03-05T18:47:10Z | [
"python",
"list",
"append"
] |
Python list entries are overridden by last appended entry | 2,389,094 | <p>I've got this code:</p>
<pre><code>def __parse(self):
for line in self.lines:
r = Record(line)
self.records[len(self.records):] = [r]
print self.records[len(self.records)-1].getValue() # Works fine!
print self.record[0].getValue() # Gives the same as
print self.record[1].... | 0 | 2010-03-05T18:40:44Z | 2,389,126 | <p>Does it still happen if you replace it with the following:</p>
<pre><code>self.record = [Record(l) for l in self.lines]
</code></pre>
<p><strong>EDIT:</strong></p>
<p>Something <em>must</em> be wrong in <code>Record</code> since the code there does work, even if it makes experienced coders weep when they read it.... | 1 | 2010-03-05T18:47:43Z | [
"python",
"list",
"append"
] |
Python list entries are overridden by last appended entry | 2,389,094 | <p>I've got this code:</p>
<pre><code>def __parse(self):
for line in self.lines:
r = Record(line)
self.records[len(self.records):] = [r]
print self.records[len(self.records)-1].getValue() # Works fine!
print self.record[0].getValue() # Gives the same as
print self.record[1].... | 0 | 2010-03-05T18:40:44Z | 2,389,395 | <p>The Record class is broken, you are always returning the same object.</p>
<p>Without seeing the code for Record it's impossible to guess</p>
<p>Perhaps you are using a list or a dict as default parameter to <code>__init__</code> and returning that with <code>getValue()</code>.</p>
<p>Another possibility is that <... | 0 | 2010-03-05T19:30:09Z | [
"python",
"list",
"append"
] |
Python list entries are overridden by last appended entry | 2,389,094 | <p>I've got this code:</p>
<pre><code>def __parse(self):
for line in self.lines:
r = Record(line)
self.records[len(self.records):] = [r]
print self.records[len(self.records)-1].getValue() # Works fine!
print self.record[0].getValue() # Gives the same as
print self.record[1].... | 0 | 2010-03-05T18:40:44Z | 2,389,606 | <p>Ok, so I'll post the code for the Record class for clarification, too.</p>
<blockquote>
<p>class Record:</p>
<pre><code>record = {}
line = ""
def __init__(self,line):
self.line = line
self.__parse()
def __parse(self):
fieldnames = ['from','to','value','error']
fields = self.line.split(',')
... | 0 | 2010-03-05T20:01:37Z | [
"python",
"list",
"append"
] |
Python list entries are overridden by last appended entry | 2,389,094 | <p>I've got this code:</p>
<pre><code>def __parse(self):
for line in self.lines:
r = Record(line)
self.records[len(self.records):] = [r]
print self.records[len(self.records)-1].getValue() # Works fine!
print self.record[0].getValue() # Gives the same as
print self.record[1].... | 0 | 2010-03-05T18:40:44Z | 2,389,647 | <p>Ahue, you have mutable objects in the <em>shared</em> class namespace -- a very common misconception when starting out with python. Move the initialization of <code>records = []</code> in <code>CsvSet</code> into its <code>__init__</code> function, and move <code>record = {}</code> into <code>Record</code> <code>__... | 1 | 2010-03-05T20:08:57Z | [
"python",
"list",
"append"
] |
Python list entries are overridden by last appended entry | 2,389,094 | <p>I've got this code:</p>
<pre><code>def __parse(self):
for line in self.lines:
r = Record(line)
self.records[len(self.records):] = [r]
print self.records[len(self.records)-1].getValue() # Works fine!
print self.record[0].getValue() # Gives the same as
print self.record[1].... | 0 | 2010-03-05T18:40:44Z | 2,389,656 | <p>Record class is broken. You use a class variable (Record.record) instead of an instance attribute. Class variable is one for all instances and you want different <code>self.record</code> for each instance.</p>
<p>Move the:</p>
<pre><code>record = {}
line = ""
</code></pre>
<p>lines into the constructor (indented ... | 1 | 2010-03-05T20:10:42Z | [
"python",
"list",
"append"
] |
Logging in worker threads spawned from a pylons application does not seem to work | 2,389,106 | <p>I have a pylons application where, under certain cirumstances I want to spawn multiple worker threads to process items in a queue. Right now we aren't making use of a ThreadPool (would be ideal, but we'll add that in later). The main problem is that the worker threads logging does not get written to the log files.</... | 0 | 2010-03-05T18:43:03Z | 2,389,754 | <p>You can try to pass a <em>log</em> variable to the thread through the arguments(<em>args</em>).</p>
| 0 | 2010-03-05T20:31:58Z | [
"python",
"multithreading",
"logging",
"pylons"
] |
Logging in worker threads spawned from a pylons application does not seem to work | 2,389,106 | <p>I have a pylons application where, under certain cirumstances I want to spawn multiple worker threads to process items in a queue. Right now we aren't making use of a ThreadPool (would be ideal, but we'll add that in later). The main problem is that the worker threads logging does not get written to the log files.</... | 0 | 2010-03-05T18:43:03Z | 2,390,197 | <p>One thing to note about logging is that if an exception occurs while emitting a log event (for whatever reason) the exception is typically swallowed, and not allowed to potentially bring down an application just because of a logging error. (It depends on the handlers used and the value of <code>logging.raiseExceptio... | 1 | 2010-03-05T21:54:01Z | [
"python",
"multithreading",
"logging",
"pylons"
] |
Python string decoding issue | 2,389,410 | <p>I am trying to parse a CSV file containing some data, mostly numeral but with some strings - which I do not know their encoding, but I do know they are in Hebrew.</p>
<p>Eventually I need to know the encoding so I can unicode the strings, print them, and perhaps throw them into a database later on.</p>
<p>I tried ... | 3 | 2010-03-05T19:32:03Z | 2,389,556 | <p>Is <code>someString</code> is maybe not a normal string, but a unicode string, like you would have us believe with your <code>sampleString</code>?</p>
<pre><code>>>> print '\xe0\xe1\xe2\xe3\xe4'.decode('cp1255')
<hebrew characters>
>>> print u'\xe0\xe1\xe2\xe3\xe4'.decode('cp1255')
Tracebac... | 0 | 2010-03-05T19:54:06Z | [
"python",
"string",
"unicode",
"character-encoding"
] |
Python string decoding issue | 2,389,410 | <p>I am trying to parse a CSV file containing some data, mostly numeral but with some strings - which I do not know their encoding, but I do know they are in Hebrew.</p>
<p>Eventually I need to know the encoding so I can unicode the strings, print them, and perhaps throw them into a database later on.</p>
<p>I tried ... | 3 | 2010-03-05T19:32:03Z | 2,389,563 | <p>You're getting an <strong>encode</strong> error when printing, so most likely it's decoding fine, you just can't print out the result properly. Try running <code>chcp 65001</code> at the command prompt before starting the Python code.</p>
| 0 | 2010-03-05T19:55:33Z | [
"python",
"string",
"unicode",
"character-encoding"
] |
Python string decoding issue | 2,389,410 | <p>I am trying to parse a CSV file containing some data, mostly numeral but with some strings - which I do not know their encoding, but I do know they are in Hebrew.</p>
<p>Eventually I need to know the encoding so I can unicode the strings, print them, and perhaps throw them into a database later on.</p>
<p>I tried ... | 3 | 2010-03-05T19:32:03Z | 2,389,567 | <p>When you decode the string to unicode with <code>someString.decode('cp1255')</code>, you have an abstract representation of some Hebrew text in unicode. (This part happens successfully!) When you use <code>print</code>, you need a concrete, encoded representation in a specific encoding. It looks like your problem is... | 3 | 2010-03-05T19:56:15Z | [
"python",
"string",
"unicode",
"character-encoding"
] |
Python string decoding issue | 2,389,410 | <p>I am trying to parse a CSV file containing some data, mostly numeral but with some strings - which I do not know their encoding, but I do know they are in Hebrew.</p>
<p>Eventually I need to know the encoding so I can unicode the strings, print them, and perhaps throw them into a database later on.</p>
<p>I tried ... | 3 | 2010-03-05T19:32:03Z | 2,389,643 | <p>This is what's happening:</p>
<ul>
<li>sampleString is a byte string (cp1255 encoded)</li>
<li><code>sampleString.decode("cp1255")</code> decodes (decode==bytes -> unicode string) the byte string to a unicode string</li>
<li><code>print sampleString.decode("cp1255")</code> attempts to print the unicode string to st... | 12 | 2010-03-05T20:08:02Z | [
"python",
"string",
"unicode",
"character-encoding"
] |
Python XMPP server library | 2,389,751 | <p>I know there are several libraries to connect to XMPP servers, but is there an XMPP server library somewhere written in Python?</p>
| 2 | 2010-03-05T20:30:34Z | 2,389,772 | <p>A quick google search reveals:</p>
<ul>
<li><p><a href="http://code.google.com/p/pretzel/" rel="nofollow">http://code.google.com/p/pretzel/</a></p>
<blockquote>
<p>An XMPP server written on the Twisted Python framework</p>
</blockquote></li>
<li><p><a href="http://code.google.com/p/pjabberd/" rel="nofollow">http... | 4 | 2010-03-05T20:36:08Z | [
"python",
"xmpp"
] |
Python XMPP server library | 2,389,751 | <p>I know there are several libraries to connect to XMPP servers, but is there an XMPP server library somewhere written in Python?</p>
| 2 | 2010-03-05T20:30:34Z | 9,092,202 | <p>It seems like that there is a new project on github:</p>
<p><a href="https://github.com/thisismedium/python-xmpp-server" rel="nofollow">python-xmpp-server</a></p>
<pre><code>An XMPP Server written in Python.
</code></pre>
<p>Personally I'm modifying it to provide an XMPP interface to the service I'm building, an... | 2 | 2012-02-01T07:16:38Z | [
"python",
"xmpp"
] |
python: inheriting or composition | 2,389,816 | <p>Let's say that I have <code>class</code>, that uses some functionality of <code>dict</code>. I used to composite a <code>dict</code> object inside and provide some access from the outside, but recently thought about simply inheriting <code>dict</code> and adding some attributes and methods that I might require. Is i... | 13 | 2010-03-05T20:44:22Z | 2,389,836 | <p>Both are good, but I'd prefer inheriting, as it will mean less code (which is always good as long as it is readable).</p>
<p><a href="http://diveintopython.net/object_oriented_framework/userdict.html" rel="nofollow">Dive into Python has a very relevant example</a>.</p>
<p>On Python 2.2 and prior, you couldn't subc... | 3 | 2010-03-05T20:49:37Z | [
"python",
"inheritance",
"composition",
"dictionary"
] |
python: inheriting or composition | 2,389,816 | <p>Let's say that I have <code>class</code>, that uses some functionality of <code>dict</code>. I used to composite a <code>dict</code> object inside and provide some access from the outside, but recently thought about simply inheriting <code>dict</code> and adding some attributes and methods that I might require. Is i... | 13 | 2010-03-05T20:44:22Z | 2,389,871 | <p>Inheritance is very often abused. Unless your class is meant to be used as a generic dictionary with extra functionality, I would say composition is the way to go.</p>
<p>Saving forwarding calls is usually not a good enough reason for choosing inheritance.</p>
<p>From the Design Pattern book:</p>
<blockquote>
<... | 10 | 2010-03-05T20:57:40Z | [
"python",
"inheritance",
"composition",
"dictionary"
] |
python: inheriting or composition | 2,389,816 | <p>Let's say that I have <code>class</code>, that uses some functionality of <code>dict</code>. I used to composite a <code>dict</code> object inside and provide some access from the outside, but recently thought about simply inheriting <code>dict</code> and adding some attributes and methods that I might require. Is i... | 13 | 2010-03-05T20:44:22Z | 2,389,917 | <p>You really have to weigh out the cost and scope of what you're trying to do. Inheriting from <code>dict</code> because you want dictionary-like behavior is quick and easy but prone to limitations such as causing objects created from your class to be unhashable.</p>
<p>So for example, if you are going to need to se... | 3 | 2010-03-05T21:05:36Z | [
"python",
"inheritance",
"composition",
"dictionary"
] |
python: inheriting or composition | 2,389,816 | <p>Let's say that I have <code>class</code>, that uses some functionality of <code>dict</code>. I used to composite a <code>dict</code> object inside and provide some access from the outside, but recently thought about simply inheriting <code>dict</code> and adding some attributes and methods that I might require. Is i... | 13 | 2010-03-05T20:44:22Z | 2,390,095 | <p>Should <code>isinstance(my_object, dict)</code> return True or False? In other words, if you accidentally give one of the objects to something that wants a <code>dict</code>, should it blithely try to use it as a <code>dict</code>? Probably not, so use composition.</p>
| 3 | 2010-03-05T21:34:06Z | [
"python",
"inheritance",
"composition",
"dictionary"
] |
Python Decimals format | 2,389,846 | <p>WHat is a good way to format a python decimal like this way? </p>
<p>1.00 --> '1'<br>
1.20 --> '1.2'<br>
1.23 --> '1.23'<br>
1.234 --> '1.23'<br>
1.2345 --> '1.23'</p>
| 29 | 2010-03-05T20:51:59Z | 2,389,916 | <p>Just use Python's standard <a href="http://docs.python.org/library/stdtypes.html#str.format" rel="nofollow">string formatting methods</a>:</p>
<pre><code>>>> "{0:.2}".format(1.234232)
'1.2'
>>> "{0:.3}".format(1.234232)
'1.23'
</code></pre>
<p>If you are using a Python version under 2.6, use</p>
... | 0 | 2010-03-05T21:05:09Z | [
"python",
"decimal"
] |
Python Decimals format | 2,389,846 | <p>WHat is a good way to format a python decimal like this way? </p>
<p>1.00 --> '1'<br>
1.20 --> '1.2'<br>
1.23 --> '1.23'<br>
1.234 --> '1.23'<br>
1.2345 --> '1.23'</p>
| 29 | 2010-03-05T20:51:59Z | 2,389,956 | <p>Here's a function that will do the trick:</p>
<pre><code>def myformat(x):
return ('%.2f' % x).rstrip('0').rstrip('.')
</code></pre>
<p>And here are your examples:</p>
<pre><code>>>> myformat(1.00)
'1'
>>> myformat(1.20)
'1.2'
>>> myformat(1.23)
'1.23'
>>> myformat(1.234)
'1... | 9 | 2010-03-05T21:11:35Z | [
"python",
"decimal"
] |
Python Decimals format | 2,389,846 | <p>WHat is a good way to format a python decimal like this way? </p>
<p>1.00 --> '1'<br>
1.20 --> '1.2'<br>
1.23 --> '1.23'<br>
1.234 --> '1.23'<br>
1.2345 --> '1.23'</p>
| 29 | 2010-03-05T20:51:59Z | 2,390,047 | <p>If you have Python 2.6 or newer, use <a href="http://docs.python.org/library/string.html#format-string-syntax"><code>format</code></a>:</p>
<pre><code>'{0:.3g}'.format(num)
</code></pre>
<p>For Python 2.5 or older:</p>
<pre><code>'%.3g'%(num)
</code></pre>
<p>Explanation:</p>
<p><code>{0}</code>tells <code>form... | 62 | 2010-03-05T21:25:06Z | [
"python",
"decimal"
] |
Python Decimals format | 2,389,846 | <p>WHat is a good way to format a python decimal like this way? </p>
<p>1.00 --> '1'<br>
1.20 --> '1.2'<br>
1.23 --> '1.23'<br>
1.234 --> '1.23'<br>
1.2345 --> '1.23'</p>
| 29 | 2010-03-05T20:51:59Z | 4,313,951 | <p>Only first part of Justin's answer is correct.
Using "%.3g" will not work for all cases as .3 is not the precision, but total number of digits. Try it for numbers like 1000.123 and it breaks.</p>
<p>So, I would use what Justin is suggesting:</p>
<pre><code>>>> ('%.4f' % 12340.123456).rstrip('0').rstrip('.... | 13 | 2010-11-30T12:51:36Z | [
"python",
"decimal"
] |
GWT Request Builder problem (same site policy issue?) | 2,389,999 | <p>I am trying out GWT in this 'configuration':</p>
<p>1) I have written a server backend in python which will produce json output (running at localhot:8094)</p>
<p>2) I have written a very simple GWT app that will use RequestBuilder to set GET to the python server (in development mode of the GWT eclipse plugin, it i... | 1 | 2010-03-05T21:17:58Z | 2,390,445 | <p>1) Yes it is, while the host is the same, you are trying to access a different port - SOP doesn't allow that. You're probably getting JavaScript exceptions - check Firebug's console or something similar.</p>
<p>2) Follow the <a href="http://code.google.com/webtoolkit/doc/latest/FAQ_DebuggingAndCompiling.html#How_do... | 2 | 2010-03-05T22:40:31Z | [
"python",
"json",
"gwt",
"same-origin-policy"
] |
GWT Request Builder problem (same site policy issue?) | 2,389,999 | <p>I am trying out GWT in this 'configuration':</p>
<p>1) I have written a server backend in python which will produce json output (running at localhot:8094)</p>
<p>2) I have written a very simple GWT app that will use RequestBuilder to set GET to the python server (in development mode of the GWT eclipse plugin, it i... | 1 | 2010-03-05T21:17:58Z | 2,420,792 | <p>yep this will fail due to SOP. What HTTP response code do you get? Normally in this case in comes back as 0 instead of 200 (OK). A solutions may be to use a JSONP approach I wrote a bit on JSONP with GWT as part of this article: <a href="http://www.bristol-gtug.org/?p=76" rel="nofollow">http://www.bristol-gtug.org/?... | 1 | 2010-03-10T21:33:59Z | [
"python",
"json",
"gwt",
"same-origin-policy"
] |
GWT Request Builder problem (same site policy issue?) | 2,389,999 | <p>I am trying out GWT in this 'configuration':</p>
<p>1) I have written a server backend in python which will produce json output (running at localhot:8094)</p>
<p>2) I have written a very simple GWT app that will use RequestBuilder to set GET to the python server (in development mode of the GWT eclipse plugin, it i... | 1 | 2010-03-05T21:17:58Z | 3,127,292 | <p>This might be too late. If you are not accessing local resources using a relative path and such, you are right, it's subjected to SOP (same origin policy). The -no-server flag won't be of much help to resolve this issue. To by-pass this issue, read <a href="http://code.google.com/p/google-web-toolkit-doc-1-5/wiki/FA... | 1 | 2010-06-27T12:10:00Z | [
"python",
"json",
"gwt",
"same-origin-policy"
] |
PSP class import + MySQL connect | 2,390,158 | <p>Ok so im trying to import a class i made which connects to a MySQL database the class code is shown below:</p>
<pre><code>class connection
def__init__( self ):
self.cnx = MySQLdb.connect(user='xxx',host='xxx',passwd='xxx',db='xxx')
</code></pre>
<p>All of the parameters for the mysql connection are cor... | 0 | 2010-03-05T21:47:43Z | 2,390,248 | <p>You are horribly, horribly confused as to how modules and classes work. Please read and work through at least the <a href="http://docs.python.org/tutorial/modules.html" rel="nofollow">modules section</a> and the <a href="http://docs.python.org/tutorial/classes.html" rel="nofollow">classes section</a> of the Python t... | 0 | 2010-03-05T22:02:31Z | [
"python",
"mysql",
"class",
"python-server-pages"
] |
PSP class import + MySQL connect | 2,390,158 | <p>Ok so im trying to import a class i made which connects to a MySQL database the class code is shown below:</p>
<pre><code>class connection
def__init__( self ):
self.cnx = MySQLdb.connect(user='xxx',host='xxx',passwd='xxx',db='xxx')
</code></pre>
<p>All of the parameters for the mysql connection are cor... | 0 | 2010-03-05T21:47:43Z | 2,390,269 | <p>Try replacing</p>
<pre><code>cur = cnx.cursor()
</code></pre>
<p>with</p>
<pre><code>con=cnx_class.connection()
cur=con.cnx.cursor()
</code></pre>
<p>You can also replace</p>
<pre><code>rows = cur.fetchall()
for row in rows:
</code></pre>
<p>with</p>
<pre><code>for row in cur.fetchall():
</code></pre>
<p>sin... | 0 | 2010-03-05T22:05:23Z | [
"python",
"mysql",
"class",
"python-server-pages"
] |
Compressed xml on soappy | 2,390,184 | <p>I'm developing an application that uses webservices in python, both sides (server and client) are developed in Python and uses SOAPpy for the webservices, but, you know, the xml is too verbose, I want to compress it, but as far as I have searched in google I can't find something helpful.</p>
| 0 | 2010-03-05T21:51:59Z | 2,391,638 | <p>You can add HTTP headers to SOAPpy call as shown <a href="http://code.activestate.com/recipes/444758-how-to-add-cookiesheaders-to-soappy-calls/" rel="nofollow">here</a> (this example sends cookies, but you can generalize it to add different headers) -- to request compression, add header <code>Accept-Encoding: gzip</... | 2 | 2010-03-06T06:49:57Z | [
"python",
"compression",
"web-services",
"soappy"
] |
Python: wingIDE syntax highlighting customization | 2,390,219 | <p>I'm using the free version of <a href="http://www.wingware.com/" rel="nofollow">wingIDE</a>. I am trying to customize individual syntax highlighting colors (comments, strings, constants, normal text, etc). I see the generic color changes for 'background,selected text", etc, but nothing that lets me get down to speci... | 3 | 2010-03-05T21:56:35Z | 2,390,551 | <p>In the full version what you need is in Preferences->User Interface->Colors->Syntax Formatting.</p>
<p>That's the same place as the background and selected text colour selection, so I'd guess it really is missing from the free version. I'm using the latest Professional version (3.2.4) and I've changed my syntax hig... | 3 | 2010-03-05T22:59:05Z | [
"python",
"syntax-highlighting",
"wing-ide"
] |
Collaborative Filtering: Non-Personalized item-to-item similarity | 2,390,312 | <p>I'm trying to compute item-to-item similarity along the lines of Amazon's "Customers who viewed/purchased X have also viewed/purchased Y and Z". All of the examples and references I've seen are for either computing item similarity for ranked items, for finding user-user similarity, or for finding recommended items ... | 3 | 2010-03-05T22:14:52Z | 2,390,397 | <p>There's a good <a href="http://oreilly.com/catalog/9780596529321" rel="nofollow">O'Reilly book</a> on this topic. While the whitepaper might lay the logic out in pseudo-code like that, I don't think that approach would scale very well. The calculations are all probability calculations, so things like <a href="http:/... | 3 | 2010-03-05T22:32:00Z | [
"python",
"algorithm",
"similarity",
"recommendation-engine",
"collaborative-filtering"
] |
Collaborative Filtering: Non-Personalized item-to-item similarity | 2,390,312 | <p>I'm trying to compute item-to-item similarity along the lines of Amazon's "Customers who viewed/purchased X have also viewed/purchased Y and Z". All of the examples and references I've seen are for either computing item similarity for ranked items, for finding user-user similarity, or for finding recommended items ... | 3 | 2010-03-05T22:14:52Z | 5,295,153 | <p>@Neil or whoever comes to this question later on:</p>
<p>The choice of similarity metric is up to you and you might want to leave it malleable for the future. Check out the Wikipedia article on Frobenius norm for a start. Or as in the link you submitted, the Jaccard coefficient <code>cos(I1,I2)</code>.</p>
<p>User... | 2 | 2011-03-14T05:41:27Z | [
"python",
"algorithm",
"similarity",
"recommendation-engine",
"collaborative-filtering"
] |
Collaborative Filtering: Non-Personalized item-to-item similarity | 2,390,312 | <p>I'm trying to compute item-to-item similarity along the lines of Amazon's "Customers who viewed/purchased X have also viewed/purchased Y and Z". All of the examples and references I've seen are for either computing item similarity for ranked items, for finding user-user similarity, or for finding recommended items ... | 3 | 2010-03-05T22:14:52Z | 10,561,506 | <p>Let's understand Item-to-Item Collaborative Filtering.
suppose we have purchase matrix </p>
<pre><code> Item1 Item2 ... ItemN
User1 0 1 ... 0
User2 1 1 ... 0
.
.
.
UserM 1 0 ... 0
</code></pre>
<p>Then we can calculate Item similarity using column vector, e.g use ... | 4 | 2012-05-12T06:11:12Z | [
"python",
"algorithm",
"similarity",
"recommendation-engine",
"collaborative-filtering"
] |
Most efficent way to create all possible combinations of four lists in Python? | 2,390,316 | <p>I have four different lists. <code>headers</code>, <code>descriptions</code>, <code>short_descriptions</code> and <code>misc</code>. I want to combine these into all the possible ways to print out:</p>
<pre><code>header\n
description\n
short_description\n
misc
</code></pre>
<p>like if i had (i'm skipping short_des... | 5 | 2010-03-05T22:15:29Z | 2,390,326 | <p>Is this what you're looking for?
<a href="http://docs.python.org/library/itertools.html#itertools.product" rel="nofollow">http://docs.python.org/library/itertools.html#itertools.product</a></p>
| 10 | 2010-03-05T22:17:40Z | [
"python",
"algorithm"
] |
Most efficent way to create all possible combinations of four lists in Python? | 2,390,316 | <p>I have four different lists. <code>headers</code>, <code>descriptions</code>, <code>short_descriptions</code> and <code>misc</code>. I want to combine these into all the possible ways to print out:</p>
<pre><code>header\n
description\n
short_description\n
misc
</code></pre>
<p>like if i had (i'm skipping short_des... | 5 | 2010-03-05T22:15:29Z | 2,390,334 | <p>Have a look to the <strong>itertools</strong> module, it contains functions to get combinations and permutations from any iterables.</p>
| 0 | 2010-03-05T22:19:21Z | [
"python",
"algorithm"
] |
Most efficent way to create all possible combinations of four lists in Python? | 2,390,316 | <p>I have four different lists. <code>headers</code>, <code>descriptions</code>, <code>short_descriptions</code> and <code>misc</code>. I want to combine these into all the possible ways to print out:</p>
<pre><code>header\n
description\n
short_description\n
misc
</code></pre>
<p>like if i had (i'm skipping short_des... | 5 | 2010-03-05T22:15:29Z | 2,390,345 | <pre><code>import itertools
headers = ['Hello there', 'Hi there!']
description = ['I like pie', 'Ho ho ho']
for p in itertools.product(headers,description):
print('\n'.join(p)+'\n')
</code></pre>
| 4 | 2010-03-05T22:22:17Z | [
"python",
"algorithm"
] |
Most efficent way to create all possible combinations of four lists in Python? | 2,390,316 | <p>I have four different lists. <code>headers</code>, <code>descriptions</code>, <code>short_descriptions</code> and <code>misc</code>. I want to combine these into all the possible ways to print out:</p>
<pre><code>header\n
description\n
short_description\n
misc
</code></pre>
<p>like if i had (i'm skipping short_des... | 5 | 2010-03-05T22:15:29Z | 2,390,347 | <p>A generator expression to do that:</p>
<pre><code>for h, d in ((h,d) for h in headers for d in description):
print h
print d
</code></pre>
| 3 | 2010-03-05T22:22:53Z | [
"python",
"algorithm"
] |
Most efficent way to create all possible combinations of four lists in Python? | 2,390,316 | <p>I have four different lists. <code>headers</code>, <code>descriptions</code>, <code>short_descriptions</code> and <code>misc</code>. I want to combine these into all the possible ways to print out:</p>
<pre><code>header\n
description\n
short_description\n
misc
</code></pre>
<p>like if i had (i'm skipping short_des... | 5 | 2010-03-05T22:15:29Z | 2,428,940 | <pre><code>>>> h = 'h1 h2 h3'.split()
>>> h
['h1', 'h2', 'h3']
>>> d = 'd1 d2'.split()
>>> s = 's1 s2 s3'.split()
>>> lists = [h, d, s]
>>> from itertools import product
>>> for hds in product(*lists):
print(', '.join(hds))
h1, d1, s1
h1, d1, s2
h1, d1... | 0 | 2010-03-11T21:47:10Z | [
"python",
"algorithm"
] |
Regex + Python to remove specific trailing and ending characters from value in tab delimited file | 2,390,501 | <p>It's been years (and years) since I've done any regex, so turning to experts on here since it's likely a trivial exercise :)</p>
<p>I have a tab delimited file and on each line I have a certain fields that have values such as:</p>
<ul>
<li>foo</li>
<li>bar </li>
<li>b"foo's bar"</li>
<li>b'bar foo'</li>
<li>b'carb... | 0 | 2010-03-05T22:50:12Z | 2,390,541 | <p>(^|\t)b[\"']
should match the leadings, and for the trailing:</p>
<p>\"'
should do it</p>
<p>In Python, you do:</p>
<pre><code>import re
r1 = re.compile("(^|\t)b[\"']")
r2 = re.compile("[\"'](\t|$)")
</code></pre>
<p>then just use</p>
<pre><code>r1.sub("\\1", yourString)
r2.sub("\\1", yourString)
</code></pre>
| 1 | 2010-03-05T22:57:53Z | [
"python",
"regex",
"python-3.x"
] |
Regex + Python to remove specific trailing and ending characters from value in tab delimited file | 2,390,501 | <p>It's been years (and years) since I've done any regex, so turning to experts on here since it's likely a trivial exercise :)</p>
<p>I have a tab delimited file and on each line I have a certain fields that have values such as:</p>
<ul>
<li>foo</li>
<li>bar </li>
<li>b"foo's bar"</li>
<li>b'bar foo'</li>
<li>b'carb... | 0 | 2010-03-05T22:50:12Z | 2,390,578 | <p>for each line you can use</p>
<pre><code>re.sub(r'''(?<![^\t\n])\W*b(["'])(.*)\1\W*(?![^\t\n])''', r'\2', line)
</code></pre>
<p>and for bonus points:</p>
<pre><code>import re
pattern = re.compile(r'''(?<![^\t\n])\W*b(["'])(.*?)\1\W*?(?![^\t\n])''')
with open('outfile', 'w') as outfile:
for line in ope... | 1 | 2010-03-05T23:05:37Z | [
"python",
"regex",
"python-3.x"
] |
Regex + Python to remove specific trailing and ending characters from value in tab delimited file | 2,390,501 | <p>It's been years (and years) since I've done any regex, so turning to experts on here since it's likely a trivial exercise :)</p>
<p>I have a tab delimited file and on each line I have a certain fields that have values such as:</p>
<ul>
<li>foo</li>
<li>bar </li>
<li>b"foo's bar"</li>
<li>b'bar foo'</li>
<li>b'carb... | 0 | 2010-03-05T22:50:12Z | 2,390,842 | <pre><code>>>> "b\"foo's bar\"".replace('b"',"").replace("b'","").rstrip("\"'")
"foo's bar"
>>> "b'bar foo'".replace('b"',"").replace("b'","").rstrip("\"'")
'bar foo'
>>>
</code></pre>
| 0 | 2010-03-06T00:28:14Z | [
"python",
"regex",
"python-3.x"
] |
only parse a specific subtree of an XML file | 2,390,611 | <p>I have a massive XML file. However, I'm only interested in a single small subtree of this massive tree. I want to parse this subtree, but I don't want to waste time parsing the entire massive tree when I'm going to only be using a small part of it. </p>
<p>Ideally, I'd want to scan through the file until I find the... | 2 | 2010-03-05T23:14:41Z | 2,390,760 | <p>I get the impression that iterparse is what you want. Looking at the section "Selective tag events" at <a href="http://lxml.de/parsing.html" rel="nofollow">http://lxml.de/parsing.html</a> it seems like that gives you what you desire:</p>
<pre><code>context = etree.iterparse(xmlfile, tag="yourSubTree")
action, elem ... | 1 | 2010-03-06T00:00:40Z | [
"python",
"xml",
"parsing",
"subtree"
] |
only parse a specific subtree of an XML file | 2,390,611 | <p>I have a massive XML file. However, I'm only interested in a single small subtree of this massive tree. I want to parse this subtree, but I don't want to waste time parsing the entire massive tree when I'm going to only be using a small part of it. </p>
<p>Ideally, I'd want to scan through the file until I find the... | 2 | 2010-03-05T23:14:41Z | 2,390,784 | <p>Iterparse will still require parsing everything up to the subtree you want. It might be more efficient to extract the subtree before you feed it into the parser with a regular expression. You might want to try writing a sax parser. Sax is probably slower than lxml, but it won't use much memory, so in some cases... | 0 | 2010-03-06T00:09:17Z | [
"python",
"xml",
"parsing",
"subtree"
] |
Is there a way to transparently perform validation on SQLAlchemy objects? | 2,390,753 | <p>Is there a way to perform validation on an object after (or as) the properties are set but before the session is committed?</p>
<p>For instance, I have a domain model <code>Device</code> that has a <code>mac</code> property. I would like to ensure that the <code>mac</code> property contains a valid and sanitized ma... | 15 | 2010-03-05T23:58:23Z | 2,391,495 | <p>"It looks like the Pythonic approach is to do most things as properties"</p>
<p>It varies, but that's close.</p>
<p>"If I had coded this in PHP or Java, I would probably have opted to create getter/setter methods..."</p>
<p>Good. That's Pythonic enough. Your getter and setter functions are bound up in a propert... | 1 | 2010-03-06T05:50:15Z | [
"python",
"validation",
"model",
"dns",
"sqlalchemy"
] |
Is there a way to transparently perform validation on SQLAlchemy objects? | 2,390,753 | <p>Is there a way to perform validation on an object after (or as) the properties are set but before the session is committed?</p>
<p>For instance, I have a domain model <code>Device</code> that has a <code>mac</code> property. I would like to ensure that the <code>mac</code> property contains a valid and sanitized ma... | 15 | 2010-03-05T23:58:23Z | 4,361,919 | <p>Yes. This can be done nicely using a MapperExtension.</p>
<pre><code># uses sqlalchemy hooks to data model class specific validators before update and insert
class ValidationExtension( sqlalchemy.orm.interfaces.MapperExtension ):
def before_update(self, mapper, connection, instance):
"""not every instan... | 7 | 2010-12-05T23:17:26Z | [
"python",
"validation",
"model",
"dns",
"sqlalchemy"
] |
Is there a way to transparently perform validation on SQLAlchemy objects? | 2,390,753 | <p>Is there a way to perform validation on an object after (or as) the properties are set but before the session is committed?</p>
<p>For instance, I have a domain model <code>Device</code> that has a <code>mac</code> property. I would like to ensure that the <code>mac</code> property contains a valid and sanitized ma... | 15 | 2010-03-05T23:58:23Z | 18,222,696 | <p>You can add data validation inside your SQLAlchemy classes using the <code>@validates()</code> decorator.</p>
<p>From the docs - <a href="http://docs.sqlalchemy.org/en/rel_0_8/orm/mapper_config.html#simple-validators">Simple Validators</a>:</p>
<blockquote>
<p>An attribute validator can raise an exception, halti... | 10 | 2013-08-14T03:23:05Z | [
"python",
"validation",
"model",
"dns",
"sqlalchemy"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.