title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Django admin, custom error message? | 1,369,548 | <p>I would like to know how to show an error message in the Django admin.</p>
<p>I have a private user section on my site where the user can create requests using "points". A request takes 1 or 2 points from the user's account (depending on the two type of request), so if the account has 0 points the user cant make an... | 7 | 2009-09-02T19:04:23Z | 1,369,683 | <p>I've used the built-in Message system for this sort of thing. This is the feature that prints the yellow bars at the top of the screen when you've added/changed an object. You can easily use it yourself:</p>
<pre><code>request.user.message_set.create(message='Message text here')
</code></pre>
<p>See <a href="http:... | 4 | 2009-09-02T19:35:04Z | [
"python",
"django",
"django-admin"
] |
Django admin, custom error message? | 1,369,548 | <p>I would like to know how to show an error message in the Django admin.</p>
<p>I have a private user section on my site where the user can create requests using "points". A request takes 1 or 2 points from the user's account (depending on the two type of request), so if the account has 0 points the user cant make an... | 7 | 2009-09-02T19:04:23Z | 1,369,708 | <p>One way to do that is by overriding the ModelForm for the admin page. That allows you to write custom validation methods and return errors of your choosing very cleanly. Like this in admin.py:</p>
<pre><code>from django.contrib import admin
from models import *
from django import forms
class MyForm(forms.ModelForm... | 18 | 2009-09-02T19:42:28Z | [
"python",
"django",
"django-admin"
] |
Django admin, custom error message? | 1,369,548 | <p>I would like to know how to show an error message in the Django admin.</p>
<p>I have a private user section on my site where the user can create requests using "points". A request takes 1 or 2 points from the user's account (depending on the two type of request), so if the account has 0 points the user cant make an... | 7 | 2009-09-02T19:04:23Z | 15,477,092 | <p>Django versions < 1.2 <a href="https://docs.djangoproject.com/en/1.4/ref/contrib/messages/" rel="nofollow">https://docs.djangoproject.com/en/1.4/ref/contrib/messages/</a></p>
<pre><code>from django.contrib import messages
messages.add_message(request, messages.INFO, 'Hello world.')
</code></pre>
| 1 | 2013-03-18T12:40:50Z | [
"python",
"django",
"django-admin"
] |
Better resources to learn buildout | 1,369,664 | <p>I am trying to grasp a bit more of buildout with <a href="http://grok.zope.org/documentation/tutorial/introduction-to-zc.buildout/tutorial-all-pages">this tutorial</a>, but unlike a tutorial, it seems like a cut and paste of presentation slides.
I don't have a really clear idea of what the purpose of buildout is, a... | 12 | 2009-09-02T19:31:15Z | 1,369,917 | <p>I quite like the <a href="http://plone.org/documentation/tutorial/buildout" rel="nofollow">Plone Buildout Tutorial</a>.</p>
<p>It gives a reasonable overview of how it all works and the ways in which you can extend a simple buildout file.</p>
<p>Here is the <a href="http://docs.plone.org/old-reference-manuals/buil... | 6 | 2009-09-02T20:22:36Z | [
"python",
"resources",
"buildout"
] |
Better resources to learn buildout | 1,369,664 | <p>I am trying to grasp a bit more of buildout with <a href="http://grok.zope.org/documentation/tutorial/introduction-to-zc.buildout/tutorial-all-pages">this tutorial</a>, but unlike a tutorial, it seems like a cut and paste of presentation slides.
I don't have a really clear idea of what the purpose of buildout is, a... | 12 | 2009-09-02T19:31:15Z | 1,485,581 | <p>The most useful resource that I found so far are the videos from pycon 2009 on Setuptools, Distutils and Buildout.</p>
<p><a href="http://pycon.blip.tv/file/2061520/" rel="nofollow">Eggs and Buildout Deployment in Python - Part 1</a></p>
<p><a href="http://pycon.blip.tv/file/2061678/" rel="nofollow">Eggs and Build... | 3 | 2009-09-28T05:44:21Z | [
"python",
"resources",
"buildout"
] |
Better resources to learn buildout | 1,369,664 | <p>I am trying to grasp a bit more of buildout with <a href="http://grok.zope.org/documentation/tutorial/introduction-to-zc.buildout/tutorial-all-pages">this tutorial</a>, but unlike a tutorial, it seems like a cut and paste of presentation slides.
I don't have a really clear idea of what the purpose of buildout is, a... | 12 | 2009-09-02T19:31:15Z | 1,684,930 | <p>Using <a href="http://www.buildout.org/" rel="nofollow">buildout.org</a> might be a good way for you to learn more about buildout.</p>
| 0 | 2009-11-06T01:56:27Z | [
"python",
"resources",
"buildout"
] |
Why is my "exploded" Python code actually running faster? | 1,369,697 | <p>I'm in an introductory comp-sci class (after doing web programming for years) and became curious about how much speed I was gaining, if any, with my one-liners.</p>
<pre><code>for line in lines:
numbers.append(eval(line.strip().split()[0]))
</code></pre>
<p>So I wrote the same thing with painfully explicit assig... | 3 | 2009-09-02T19:40:11Z | 1,369,733 | <p>Frankly speaking, the first version, where everything is in one line, is a pain to read.<br />
The second one is maybe a little too verbose (something in the middle would be appreciated) but it is definitely better.</p>
<p>I would not care too much about micro optimizations because of Python internals, and focus on... | 7 | 2009-09-02T19:46:53Z | [
"python",
"optimization"
] |
Why is my "exploded" Python code actually running faster? | 1,369,697 | <p>I'm in an introductory comp-sci class (after doing web programming for years) and became curious about how much speed I was gaining, if any, with my one-liners.</p>
<pre><code>for line in lines:
numbers.append(eval(line.strip().split()[0]))
</code></pre>
<p>So I wrote the same thing with painfully explicit assig... | 3 | 2009-09-02T19:40:11Z | 1,369,748 | <p>A one liner doesn't mean smaller or faster code. And I would expect that the eval() line would throw off performance measurements quite a bit. </p>
<p>Do you see similar performance differences without eval ?</p>
| 2 | 2009-09-02T19:49:05Z | [
"python",
"optimization"
] |
Why is my "exploded" Python code actually running faster? | 1,369,697 | <p>I'm in an introductory comp-sci class (after doing web programming for years) and became curious about how much speed I was gaining, if any, with my one-liners.</p>
<pre><code>for line in lines:
numbers.append(eval(line.strip().split()[0]))
</code></pre>
<p>So I wrote the same thing with painfully explicit assig... | 3 | 2009-09-02T19:40:11Z | 1,369,774 | <p>Your code isn't exploded in the same order. The compact version goes:</p>
<pre><code>A > B > C > D > E
</code></pre>
<p>while your exploded version goes </p>
<pre><code>B > C > A > D > E
</code></pre>
<p>The effect is that strip() is being deferred 2 steps down, which may affect performa... | 15 | 2009-09-02T19:52:16Z | [
"python",
"optimization"
] |
Why is my "exploded" Python code actually running faster? | 1,369,697 | <p>I'm in an introductory comp-sci class (after doing web programming for years) and became curious about how much speed I was gaining, if any, with my one-liners.</p>
<pre><code>for line in lines:
numbers.append(eval(line.strip().split()[0]))
</code></pre>
<p>So I wrote the same thing with painfully explicit assig... | 3 | 2009-09-02T19:40:11Z | 1,369,779 | <p>The method calls are also not in the same order:</p>
<pre><code>for line in lines:
numbers.append(eval(line.strip().split()[0]))
</code></pre>
<p>should be:</p>
<pre><code>for line in lines:
numbers.append(eval(line.split()[0].strip()))
</code></pre>
| 4 | 2009-09-02T19:53:10Z | [
"python",
"optimization"
] |
Why is my "exploded" Python code actually running faster? | 1,369,697 | <p>I'm in an introductory comp-sci class (after doing web programming for years) and became curious about how much speed I was gaining, if any, with my one-liners.</p>
<pre><code>for line in lines:
numbers.append(eval(line.strip().split()[0]))
</code></pre>
<p>So I wrote the same thing with painfully explicit assig... | 3 | 2009-09-02T19:40:11Z | 1,369,880 | <p>I agree with Roberto Liffredo; don't worry about that small of a performance improvement; code that is easier to understand, debug, and change is its own reward.</p>
<p>As for what's going on: the terse code and the expanded code don't do quite the same things. <code>line.strip().split()</code> first strips the li... | 3 | 2009-09-02T20:15:01Z | [
"python",
"optimization"
] |
Why is my "exploded" Python code actually running faster? | 1,369,697 | <p>I'm in an introductory comp-sci class (after doing web programming for years) and became curious about how much speed I was gaining, if any, with my one-liners.</p>
<pre><code>for line in lines:
numbers.append(eval(line.strip().split()[0]))
</code></pre>
<p>So I wrote the same thing with painfully explicit assig... | 3 | 2009-09-02T19:40:11Z | 1,369,924 | <p>Also, sometimes it's tricky to run benchmarks. Did you re-run the benchmarks multiple times and take the best of several runs? Is there any chance that caching effects give a performance advantage to the second Python program you run? Have you tried making your input file ten times bigger, so your program will ta... | 3 | 2009-09-02T20:24:23Z | [
"python",
"optimization"
] |
Why is my "exploded" Python code actually running faster? | 1,369,697 | <p>I'm in an introductory comp-sci class (after doing web programming for years) and became curious about how much speed I was gaining, if any, with my one-liners.</p>
<pre><code>for line in lines:
numbers.append(eval(line.strip().split()[0]))
</code></pre>
<p>So I wrote the same thing with painfully explicit assig... | 3 | 2009-09-02T19:40:11Z | 1,370,142 | <p>I haven't benchmarked it, but one factor in the time differences is that you have to do several variable lookups in the second function.</p>
<p><a href="http://www.python.org/doc/essays/list2str.html" rel="nofollow">From Python Patterns - An Optimization Anecdote</a>:</p>
<blockquote>
<p>This is because local va... | 3 | 2009-09-02T21:10:13Z | [
"python",
"optimization"
] |
Why is my "exploded" Python code actually running faster? | 1,369,697 | <p>I'm in an introductory comp-sci class (after doing web programming for years) and became curious about how much speed I was gaining, if any, with my one-liners.</p>
<pre><code>for line in lines:
numbers.append(eval(line.strip().split()[0]))
</code></pre>
<p>So I wrote the same thing with painfully explicit assig... | 3 | 2009-09-02T19:40:11Z | 1,370,822 | <p>Okay, enough theorizing. I created a file with one million lines, with random amounts of white space (0 to 4 spaces, usually 0) at beginning and end of each line. And I ran your one-liner, your expanded version, and my own list comprehension version (as fast as I know how to make it).</p>
<p>My results? (Each on... | 2 | 2009-09-03T00:14:07Z | [
"python",
"optimization"
] |
How would you query Picasa from a Google App Engine app? Data API or Url Fetch? | 1,369,861 | <p>How would you query Picasa from a Google App Engine app? Data API or Url Fetch? What are the pros and cons of using either method?</p>
<p><strong>[Edit]</strong><br />
I would like to be able to query a specific album in Picasa and list all the photos in it.
Code examples to do this in python are much appreciated.<... | 0 | 2009-09-02T20:10:47Z | 1,369,908 | <p>Your question is a little off, since the Data API is exposed through RESTful URLs, so both methods are ultimately a "URL Fetch".</p>
<p>The Data API works quite well, though. It gives you access to nearly all the functionality of Picasa, and responses are sent back and forth in well-formed, well-documented XML. Goo... | 2 | 2009-09-02T20:19:43Z | [
"python",
"api",
"google-app-engine",
"picasa",
"urlfetch"
] |
Python .pth Files Aren't Working | 1,369,947 | <p>Directories listed in my .pth configuration file aren't appearing in sys.path.</p>
<p>The contents of configuration file, named <code>some_code_dirs.pth</code>:</p>
<pre><code>/home/project
</code></pre>
<p>Paths to the file:</p>
<pre><code>/usr/lib/python2.6/site-packages/some_code_dirs.pth
/usr/lib/python2.6/s... | 6 | 2009-09-02T20:31:34Z | 1,370,034 | <p>What OS are you using? On my Ubuntu 9.04 system that directory is not in sys.path.
Try putting it into <code>/usr/lib/python2.6/dist-packages</code>. Notice that it is <strong>dist</strong> instead of <strong>site</strong>.</p>
| 4 | 2009-09-02T20:51:52Z | [
"python",
"pythonpath"
] |
Python .pth Files Aren't Working | 1,369,947 | <p>Directories listed in my .pth configuration file aren't appearing in sys.path.</p>
<p>The contents of configuration file, named <code>some_code_dirs.pth</code>:</p>
<pre><code>/home/project
</code></pre>
<p>Paths to the file:</p>
<pre><code>/usr/lib/python2.6/site-packages/some_code_dirs.pth
/usr/lib/python2.6/s... | 6 | 2009-09-02T20:31:34Z | 1,370,276 | <p>I had a <a href="http://stackoverflow.com/questions/1159650/how-to-use-a-custom-site-package-using-pth-files-for-python-2-6">similar problem</a> a while ago. Check the encoding of your pth-file. It seems that pth-files are silently ignored if encoded in UTF-8 with BOM.</p>
| 0 | 2009-09-02T21:37:43Z | [
"python",
"pythonpath"
] |
show *only* docstring in Sphinx documentation | 1,370,283 | <p>Sphinx has a feature called <code>automethod</code> that extracts the documentation from a method's docstring and embeds that into the documentation. But it not only embeds the docstring, but also the method signature (name + arguments). How do I embed <em>only</em> the docstring (excluding the method signature)?</p... | 9 | 2009-09-02T21:39:09Z | 1,384,673 | <p>I think what you're looking for is:</p>
<pre><code>from sphinx.ext import autodoc
class DocsonlyMethodDocumenter(autodoc.MethodDocumenter):
def format_args(self):
return None
autodoc.add_documenter(DocsonlyMethodDocumenter)
</code></pre>
<p>per <a href="http://bitbucket.org/birkenfeld/sphinx/src/tip/sphinx... | 14 | 2009-09-06T01:37:46Z | [
"python",
"documentation",
"python-sphinx"
] |
What is this piece of Python code doing? | 1,370,604 | <p>This following is a snippet of Python code I found that solves a mathematical problem. What exactly is it doing? I wasn't too sure what to Google for.</p>
<pre><code>x, y = x + 3 * y, 4 * x + 1 * y
</code></pre>
<p>Is this a special Python syntax?</p>
| 8 | 2009-09-02T23:03:11Z | 1,370,624 | <pre><code>x, y = x + 3 * y, 4 * x + 1 * y
</code></pre>
<p>is the equivalent of:</p>
<pre><code>x = x + 3 * y
y = 4 * x + 1 * y
</code></pre>
<p><strong>EXCEPT</strong> that it uses the original values for x and y in both calculations - because the new values for x and y aren't assigned until both calculations are ... | 16 | 2009-09-02T23:06:50Z | [
"python",
"math",
"syntax"
] |
What is this piece of Python code doing? | 1,370,604 | <p>This following is a snippet of Python code I found that solves a mathematical problem. What exactly is it doing? I wasn't too sure what to Google for.</p>
<pre><code>x, y = x + 3 * y, 4 * x + 1 * y
</code></pre>
<p>Is this a special Python syntax?</p>
| 8 | 2009-09-02T23:03:11Z | 1,370,631 | <p>It's an assignment to a <a href="http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences" rel="nofollow">tuple</a>, also called <em>sequence unpacking</em>. Probably it's clearer when you add parenthesis around the tuples:</p>
<pre><code>(x, y) = (x + 3 * y, 4 * x + 1 * y)
</code></pre>
<p>The val... | 12 | 2009-09-02T23:09:14Z | [
"python",
"math",
"syntax"
] |
What is this piece of Python code doing? | 1,370,604 | <p>This following is a snippet of Python code I found that solves a mathematical problem. What exactly is it doing? I wasn't too sure what to Google for.</p>
<pre><code>x, y = x + 3 * y, 4 * x + 1 * y
</code></pre>
<p>Is this a special Python syntax?</p>
| 8 | 2009-09-02T23:03:11Z | 1,375,316 | <p>I also recently saw this referred to as "simultaneous assignment", which seems to capture the spirit of several of the answers.</p>
| 0 | 2009-09-03T19:03:59Z | [
"python",
"math",
"syntax"
] |
group by year, month, day in a sqlalchemy | 1,370,997 | <p>I want "DBSession.query(Article).group_by(Article.created.month).all()"</p>
<p>But this query can't using</p>
<p>How do I do this using SQLAlchemy?</p>
| 9 | 2009-09-03T01:19:10Z | 1,371,029 | <p>assuming you db engine actually supports functions like <code>MONTH()</code>, you can try</p>
<pre><code>import sqlalchemy as sa
DBSession.query(Article).group_by( sa.func.year(Article.created), sa.func.month(Article.created)).all()
</code></pre>
<p>else you can group in python like</p>
<pre><code>from itertools ... | 22 | 2009-09-03T01:34:25Z | [
"python",
"sqlalchemy"
] |
group by year, month, day in a sqlalchemy | 1,370,997 | <p>I want "DBSession.query(Article).group_by(Article.created.month).all()"</p>
<p>But this query can't using</p>
<p>How do I do this using SQLAlchemy?</p>
| 9 | 2009-09-03T01:19:10Z | 3,795,778 | <p><strong>THC4k answer works</strong> but I just want to add that <code>query_result</code> need to be already <strong>sorted</strong> to get <code>itertools.groupby</code> working the way you want.</p>
<pre><code>query_result = DBSession.query(Article).order_by(Article.created).all()
</code></pre>
<p>Here is the ex... | 9 | 2010-09-25T22:05:29Z | [
"python",
"sqlalchemy"
] |
Django - flush response? | 1,371,020 | <p>I am sending an AJAX request to a Django view that can potentially take a lot of time. It goes through some well-defined steps, however, so I would like to print status indicators to the user letting it know when it is finished doing a certain thing and has moved on to the next.</p>
<p>If I was using PHP it might l... | 6 | 2009-09-03T01:29:31Z | 1,371,061 | <p>Most webservers (eg. FCGI/SCGI) do their own buffering, HTTP clients do their own, and so on. It's very difficult to actually get data flushed out in this way and for the client to actually receive it, because it's not a typical operation.</p>
<p>The closest to what you're trying to do would be to pass an iterator... | 8 | 2009-09-03T01:50:23Z | [
"python",
"django"
] |
Django - flush response? | 1,371,020 | <p>I am sending an AJAX request to a Django view that can potentially take a lot of time. It goes through some well-defined steps, however, so I would like to print status indicators to the user letting it know when it is finished doing a certain thing and has moved on to the next.</p>
<p>If I was using PHP it might l... | 6 | 2009-09-03T01:29:31Z | 1,371,078 | <p>I'm not sure you need to use the flush() function.</p>
<p>Your AJAX request should just go to a django view.</p>
<p>If your steps can be broken down, keep it simple and create a view for each step.
That way one one process completes you can update the user and start the next request via AJAX.</p>
<p><strong>views... | 4 | 2009-09-03T01:58:34Z | [
"python",
"django"
] |
Weird python behaviour on machine with ARM CPU | 1,371,228 | <p>What could possibly cause this weird python behaviour?</p>
<pre><code>Python 2.6.2 (r262:71600, May 31 2009, 03:55:41)
[GCC 3.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> .1
1251938906.2350719
>>> .1
0.23507189750671387
>>> .1
0.0
>>> ... | 10 | 2009-09-03T02:59:57Z | 1,371,551 | <p>Maybe it's compiled for the wrong <a href="http://en.wikipedia.org/wiki/ARM%5Farchitecture#VFP" rel="nofollow">VFP</a> version.</p>
<p>Or your ARM has no VFP and needs to use software emulation instead, but the python binary tries to use hardware.</p>
<p><hr /></p>
<p><strong>EDIT</strong></p>
<p>Your DS-101j bu... | 8 | 2009-09-03T05:26:21Z | [
"python",
"floating-point",
"arm"
] |
Weird python behaviour on machine with ARM CPU | 1,371,228 | <p>What could possibly cause this weird python behaviour?</p>
<pre><code>Python 2.6.2 (r262:71600, May 31 2009, 03:55:41)
[GCC 3.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> .1
1251938906.2350719
>>> .1
0.23507189750671387
>>> .1
0.0
>>> ... | 10 | 2009-09-03T02:59:57Z | 1,374,437 | <p>As zxcat said, this sounds like you're running on an ARM with no hardware-floating point and a busted soft-float library. A quick search didn't turn up what ARM variant is in the DS101j; anyone know?</p>
| 0 | 2009-09-03T16:17:14Z | [
"python",
"floating-point",
"arm"
] |
query for values based on date w/ Django ORM | 1,371,280 | <p>I have a bunch of objects that have a value and a date field: </p>
<pre><code>obj1 = Obj(date='2009-8-20', value=10)
obj2 = Obj(date='2009-8-21', value=15)
obj3 = Obj(date='2009-8-23', value=8)
</code></pre>
<p>I want this returned:</p>
<pre><code>[10, 15, 0, 8]
</code></pre>
<p>or better yet, an aggregate of th... | 1 | 2009-09-03T03:20:05Z | 1,371,478 | <pre><code>result_list = []
for day in range(20,24):
result = Obj.objects.get(date=datetime(2009, 08, day))
if result:
result_list.append(result.value)
else:
result_list.append(0)
return result_list
</code></pre>
<p>If you have more than one Obj per date, you'll need to check len(obj) a... | 0 | 2009-09-03T04:48:36Z | [
"python",
"django",
"django-orm"
] |
query for values based on date w/ Django ORM | 1,371,280 | <p>I have a bunch of objects that have a value and a date field: </p>
<pre><code>obj1 = Obj(date='2009-8-20', value=10)
obj2 = Obj(date='2009-8-21', value=15)
obj3 = Obj(date='2009-8-23', value=8)
</code></pre>
<p>I want this returned:</p>
<pre><code>[10, 15, 0, 8]
</code></pre>
<p>or better yet, an aggregate of th... | 1 | 2009-09-03T03:20:05Z | 1,371,550 | <p>This one isn't tested, since it's a bit too much of a pain to set up a Django table to test with:</p>
<pre><code>from datetime import date, timedelta
# http://www.ianlewis.org/en/python-date-range-iterator
def datetimeRange(from_date, to_date=None):
while to_date is None or from_date <= to_date:
yiel... | 3 | 2009-09-03T05:25:55Z | [
"python",
"django",
"django-orm"
] |
query for values based on date w/ Django ORM | 1,371,280 | <p>I have a bunch of objects that have a value and a date field: </p>
<pre><code>obj1 = Obj(date='2009-8-20', value=10)
obj2 = Obj(date='2009-8-21', value=15)
obj3 = Obj(date='2009-8-23', value=8)
</code></pre>
<p>I want this returned:</p>
<pre><code>[10, 15, 0, 8]
</code></pre>
<p>or better yet, an aggregate of th... | 1 | 2009-09-03T03:20:05Z | 1,372,222 | <p>If you loop through a Obj.objects.get 100 times, you're doing 100 SQL queries. Obj.objects.filter will return the results in one SQL query, but you also select all model fields. The right way to do this is to use Obj.objects.values_list, which will do this with a single query, and only select the 'values' field.</p>... | 1 | 2009-09-03T08:51:19Z | [
"python",
"django",
"django-orm"
] |
REST / JSON / XML-RPC / SOAP | 1,371,312 | <p>Sorry for being the 100000th person to ask the same question. But I guess my case is slightly distinctive.</p>
<p>The application is that we'd like to have an Android phone client on 3g and a light python web service server.</p>
<p>The phone would do most of the work and do a lot of uploading, pictures, GPS, etc e... | 4 | 2009-09-03T03:35:22Z | 1,371,337 | <p>REST mandates the general semantics and concepts. The transport and encodings are up to you. They were originally formulated on XML, but JSON is totally applicable.</p>
<p>XML-RPC / SOAP are different mechanisms, but mostly the same ideas: how to map OO APIs on top of XML and HTTP. IMHO, they're disgusting from ... | 7 | 2009-09-03T03:43:39Z | [
"python",
"android",
"service"
] |
Set Max Width for Frame with ScrolledWindow in wxPython | 1,371,510 | <p>I created a Frame object and I want to limit the width it can expand to. The only window in the frame is a ScrolledWindow object and that contains all other children. I have a lot of objects arranged with a BoxSizer oriented vertically so the ScrolledWindow object gets pretty tall. There is often a scrollbar to the ... | 0 | 2009-09-03T05:05:53Z | 1,670,856 | <p>This is a little ugly, but seems to work on Window and Linux. There is difference, though. The self.GetVirtualSize() seems to return different values on each platform. At any rate, I think this may help you.</p>
<pre><code>width, height = self.scroll.GetBestSize()
width_2, height_2 = self.GetVirtualSize()
print ... | 1 | 2009-11-03T23:36:51Z | [
"python",
"user-interface",
"wxpython"
] |
Importing external module in IronPython | 1,371,994 | <p>I'm currently working on an application written in C#, which I'm embedding IronPython in. I generally have no problems about it, but there's one thing that I don't know how to deal with. </p>
<p>I want to import an external module into the script. How can I do that? Simple <code>import ext_lib</code> doesn't work. ... | 11 | 2009-09-03T07:50:17Z | 1,372,777 | <p>Chances are that your path is set up incorrectly. From <a href="http://ironpython.codeplex.com/Wiki/View.aspx?title=FAQ">the IronPython FAQ</a>:</p>
<blockquote>
<h3>How do I use CPython standard libraries?</h3>
<p>To tell IronPython where the Python standard library is, you can add the "lib" directory of C... | 7 | 2009-09-03T11:07:58Z | [
"python",
"import",
"ironpython"
] |
Importing external module in IronPython | 1,371,994 | <p>I'm currently working on an application written in C#, which I'm embedding IronPython in. I generally have no problems about it, but there's one thing that I don't know how to deal with. </p>
<p>I want to import an external module into the script. How can I do that? Simple <code>import ext_lib</code> doesn't work. ... | 11 | 2009-09-03T07:50:17Z | 1,379,797 | <p>Before compiling a script with the PythonEngine, I add the script's directory to the engine's search path. This is what I do in the C# code:</p>
<pre><code>string dir = Path.GetDirectoryName(scriptPath);
ICollection<string> paths = engine.GetSearchPaths();
if (!String.IsNullOrWhitespac... | 18 | 2009-09-04T14:58:22Z | [
"python",
"import",
"ironpython"
] |
How to specify a configuration file for pylint under windows? | 1,372,295 | <p>I am evaluating pylint as source code checker and I would like to customize the maximum number of characters on a single line. </p>
<p>I would like to use a configuration file. I've generated a template thanks to the --generate-rcfile command and I've made my modification.</p>
<p>I am trying to run pylint --rcfile... | 13 | 2009-09-03T09:04:08Z | 1,372,445 | <p>Try setting PYLINTRC env variable.</p>
<p>I use batch:</p>
<pre><code>@echo off
set PYLINTHOME=c:\tools
set PYLINTRC=c:\etc\pylint.conf
rem c:\Python27\python.exe c:\Python27\Lib\site-packages\pylint\lint.py %1 %2 %3 %4 %5 %6 %7 %8 %9
c:\Python27\python.exe c:\Python27\Lib\site-packages\pylint\lint.py %*
</code></... | 4 | 2009-09-03T09:40:21Z | [
"python",
"pylint"
] |
How to specify a configuration file for pylint under windows? | 1,372,295 | <p>I am evaluating pylint as source code checker and I would like to customize the maximum number of characters on a single line. </p>
<p>I would like to use a configuration file. I've generated a template thanks to the --generate-rcfile command and I've made my modification.</p>
<p>I am trying to run pylint --rcfile... | 13 | 2009-09-03T09:04:08Z | 15,837,092 | <p>On Windows 7, a .pylintrc file in your home directory (typically C:\Users\myusername) will be automatically recognized.</p>
<p>Since creating a file beginning with a dot is not allowed from Windows file explorer, you can create a template using:</p>
<pre><code>pylint --generate-rcfile > .pylintrc
</code></pre>
| 6 | 2013-04-05T14:54:32Z | [
"python",
"pylint"
] |
Python Changing module variables in another module | 1,372,486 | <p>Say I am importing the module 'foo' into the module 'bar'.
Is it possible for me to change a global variable in foo inside bar? </p>
<p>Let the global variable in foo be 'arbit'.
Change arbit so that if bar were to call a function of foo that uses this variable, the updated variable is used rather than the one befo... | 0 | 2009-09-03T09:54:13Z | 1,372,516 | <p>You should be able to do:</p>
<pre><code>import foo
foo.arbit = 'new value'
</code></pre>
| 5 | 2009-09-03T10:00:10Z | [
"python",
"module"
] |
How to insert a row with autoincrement id in a multi-primary-key table? | 1,372,525 | <p>I am writing a turbogears2 application. I have a table like this:</p>
<pre><code>class Order(DeclarativeBase):
__tablename__ = 'order'
# id of order
id = Column(Integer, autoincrement=True, primary_key=True)
# buyer's id
buyer_id = Column(Integer, ForeignKey('user.user_id',
onupdate="C... | 0 | 2009-09-03T10:01:31Z | 1,372,787 | <p>If you want sequential numbers per buyer for your orders then you'll have to serialize the transactions inserting to one buyer. You can do that by acquiring exclusive lock on the buyer row:</p>
<pre><code>sess.query(Buyer.id).with_lockmode('update').get(xxx)
order_id = sess.query(func.max(Order.id)+1).filter_by(buy... | 1 | 2009-09-03T11:10:21Z | [
"python",
"sql",
"database",
"sqlalchemy"
] |
How to insert a row with autoincrement id in a multi-primary-key table? | 1,372,525 | <p>I am writing a turbogears2 application. I have a table like this:</p>
<pre><code>class Order(DeclarativeBase):
__tablename__ = 'order'
# id of order
id = Column(Integer, autoincrement=True, primary_key=True)
# buyer's id
buyer_id = Column(Integer, ForeignKey('user.user_id',
onupdate="C... | 0 | 2009-09-03T10:01:31Z | 1,372,794 | <p>You should be using a default on your column definitions</p>
<pre><code>id = Column(Integer, default = sqlexpression)
</code></pre>
<p>Where sqlexpression can be a sql expression. Here is the <a href="http://www.sqlalchemy.org/docs/05/metadata.html#pre-executed-and-inline-sql-expressions" rel="nofollow">documentat... | 1 | 2009-09-03T11:13:27Z | [
"python",
"sql",
"database",
"sqlalchemy"
] |
Algorithm to filter a set of all phrases containing in other phrase | 1,372,531 | <p>Given a set of phrases, i would like to filter the set of all phrases that contain any of the other phrases. Contained here means that if a phrase contains all the words of another phrase it should be filtered out. Order of the words within the phrase does not matter.</p>
<p>What i have so far is this:</p>
<ol>
<l... | 1 | 2009-09-03T10:02:23Z | 1,372,585 | <p>sort phrases by their contents, i.e., 'Z A' -> 'A Z', then eliminating phrases is easy going from shortest to longer ones.</p>
| 0 | 2009-09-03T10:12:19Z | [
"c#",
"java",
"c++",
"python",
"algorithm"
] |
Algorithm to filter a set of all phrases containing in other phrase | 1,372,531 | <p>Given a set of phrases, i would like to filter the set of all phrases that contain any of the other phrases. Contained here means that if a phrase contains all the words of another phrase it should be filtered out. Order of the words within the phrase does not matter.</p>
<p>What i have so far is this:</p>
<ol>
<l... | 1 | 2009-09-03T10:02:23Z | 1,372,627 | <p>You could build an index which maps words to phrases and do something like:</p>
<pre>
let matched = set of all phrases
for each word in the searched phrase
let wordMatch = all phrases containing the current word
let matched = intersection of matched and wordMatch
</pre>
<p>After this, <code>matched</code> ... | 1 | 2009-09-03T10:24:14Z | [
"c#",
"java",
"c++",
"python",
"algorithm"
] |
Algorithm to filter a set of all phrases containing in other phrase | 1,372,531 | <p>Given a set of phrases, i would like to filter the set of all phrases that contain any of the other phrases. Contained here means that if a phrase contains all the words of another phrase it should be filtered out. Order of the words within the phrase does not matter.</p>
<p>What i have so far is this:</p>
<ol>
<l... | 1 | 2009-09-03T10:02:23Z | 1,372,711 | <p>Your algo is quadratic in the number of phrases, that's probably what's slowing it down. Here I index phrases by words to get below quadratic in the common case.</p>
<pre><code># build index
foreach phrase: foreach word: phrases[word] += phrase
# use index to filter out phrases that contain all the words
# from an... | 1 | 2009-09-03T10:47:38Z | [
"c#",
"java",
"c++",
"python",
"algorithm"
] |
Algorithm to filter a set of all phrases containing in other phrase | 1,372,531 | <p>Given a set of phrases, i would like to filter the set of all phrases that contain any of the other phrases. Contained here means that if a phrase contains all the words of another phrase it should be filtered out. Order of the words within the phrase does not matter.</p>
<p>What i have so far is this:</p>
<ol>
<l... | 1 | 2009-09-03T10:02:23Z | 1,372,721 | <p>This is the problem of finding minimal values of a set of sets. The naive algorithm and problem definition looks like this:</p>
<pre><code>set(s for s in sets if not any(other < s for other in sets))
</code></pre>
<p>There are sub-quadratic algorithms to do this (such as <a href="http://citeseerx.ist.psu.edu/vi... | 1 | 2009-09-03T10:50:09Z | [
"c#",
"java",
"c++",
"python",
"algorithm"
] |
Is there a python library/module for creating a multi ssh connection? | 1,372,657 | <p>I've been searching for a library that can access multiple ssh connections at once, Ruby has a Net::SSH::Multi module that allows multiple ssh connections at once. However I rather prefer coding this in Python, are there any similar SSH module for python?</p>
| 1 | 2009-09-03T10:32:59Z | 1,372,742 | <p><a href="http://www.lag.net/paramiko/" rel="nofollow">Paramiko</a> is Python's SSH library.</p>
<p>I've never tried concurrent connections with Paramiko, but <a href="http://stackoverflow.com/questions/1185855/parallel-ssh-in-python/1188586#1188586">this answer</a> says it's possible, and <a href="http://www.packet... | 2 | 2009-09-03T10:57:45Z | [
"python",
"ruby",
"ssh"
] |
Reading a Django model's field options | 1,372,706 | <p>Is it possible to read a Django model's fields' options? For example, with the model:</p>
<pre><code>class MyModel(models.Model):
source_url = models.URLField(max_length=500)
...
</code></pre>
<p>i.e. how would I programmatically read the 'max_length' option from, say, within a view or form.</p>
<p>My cur... | 1 | 2009-09-03T10:46:27Z | 1,372,896 | <p>Do it this way.</p>
<pre><code>from models import MyModel
try:
max_length = MyModel._meta.get_field('source_url').max_length
except:
max_length = None
</code></pre>
| 5 | 2009-09-03T11:36:13Z | [
"python",
"django"
] |
Django: remove GROUP BY added with extra() method? | 1,372,890 | <p>Hi (excuse me for my bad english) !</p>
<p>When I make this:</p>
<pre><code>gallery_qs = Gallery.objects.all()\
.annotate(Count('photos'))\
.extra(select={'photo_id': 'photologue_photo.id'})
</code></pre>
<p>The sql query is :</p>
<pre><code>SELECT (photologue_photo.id) AS... | 1 | 2009-09-03T11:34:36Z | 1,375,836 | <p>I don't think you really need the extra. From Django's concept, you don't need to cherry pick specific columns while running a Django QuerySet. That logic can be done in the template side.</p>
<p>I assume you know how to push <code>galley_qs</code> to your template from your view:</p>
<pre><code># views.py
galle... | 1 | 2009-09-03T20:43:03Z | [
"python",
"sql",
"django",
"django-models",
"photologue"
] |
Django: remove GROUP BY added with extra() method? | 1,372,890 | <p>Hi (excuse me for my bad english) !</p>
<p>When I make this:</p>
<pre><code>gallery_qs = Gallery.objects.all()\
.annotate(Count('photos'))\
.extra(select={'photo_id': 'photologue_photo.id'})
</code></pre>
<p>The sql query is :</p>
<pre><code>SELECT (photologue_photo.id) AS... | 1 | 2009-09-03T11:34:36Z | 1,376,682 | <p>Why are you trying to get distinct gallery records with a photo_id annotated on them when gallery to photo ids is a many to many relationship? From what I can tell, the query you are doing would only get a single photo id for each gallery.</p>
<p>If you really do need to do the above, I think you could use distinct... | 0 | 2009-09-04T00:30:47Z | [
"python",
"sql",
"django",
"django-models",
"photologue"
] |
Beginner graphics program in Python giving 'out of stack space' error | 1,372,949 | <p>I'm currently learning Python using Zelle's Introductory text, and I'm trying to recreate one of the example programs which uses an accompanying file graphics.py. Because I'm using Python 3.1 and the text was written for 2.x though, I'm using the GraphicsPy3.py file found at <a href="http://mcsp.wartburg.edu/zelle/... | 4 | 2009-09-03T11:49:33Z | 1,373,063 | <p>There appears to be a problem with the Python 3 version of graphics.py.</p>
<p>I downloaded the Python 3 version, renamed it to graphics.py, then ran the following.</p>
<pre><code>PS C:\Users\jaraco\Desktop> python
Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on
win32
Type "help"... | 2 | 2009-09-03T12:17:36Z | [
"python"
] |
Beginner graphics program in Python giving 'out of stack space' error | 1,372,949 | <p>I'm currently learning Python using Zelle's Introductory text, and I'm trying to recreate one of the example programs which uses an accompanying file graphics.py. Because I'm using Python 3.1 and the text was written for 2.x though, I'm using the GraphicsPy3.py file found at <a href="http://mcsp.wartburg.edu/zelle/... | 4 | 2009-09-03T11:49:33Z | 1,373,069 | <p>your code has issues with buil-in <code>input</code>, when it's called with non-empty string as argument. I suspect it might have something to do with the thread setup that <code>graphics</code> does.</p>
<p>If you make Tkinter widgets to read these inputs, may be it'll solve your problem.</p>
<p>To be honest, whe... | 1 | 2009-09-03T12:18:22Z | [
"python"
] |
Beginner graphics program in Python giving 'out of stack space' error | 1,372,949 | <p>I'm currently learning Python using Zelle's Introductory text, and I'm trying to recreate one of the example programs which uses an accompanying file graphics.py. Because I'm using Python 3.1 and the text was written for 2.x though, I'm using the GraphicsPy3.py file found at <a href="http://mcsp.wartburg.edu/zelle/... | 4 | 2009-09-03T11:49:33Z | 1,383,262 | <p>After some additional research, it does appear that the call to input() does have some impact on triggering the unwanted behavior.</p>
<p>I re-wrote the program to not import the graphics module until after the input() calls were complete. In this case, I was unable to reproduce the error, and the code seemed to b... | 0 | 2009-09-05T12:49:46Z | [
"python"
] |
How do I create a variable number of variables in Python? | 1,373,164 | <p>How do I accomplish variable variables in Python? </p>
<p>Here is an elaborative manual entry, for instance: <em><a href="http://us3.php.net/manual/en/language.variables.variable.php">Variable variables</a></em></p>
<p>I have heard this is a bad idea in general though, and it is a security hole in Python. Is that ... | 96 | 2009-09-03T12:37:48Z | 1,373,185 | <p>Use dictionaries to accomplish this. Dictionaries are stores of keys and values. </p>
<pre><code>>>> dct = {'x': 1, 'y': 2, 'z': 3}
>>> dct
{'y': 2, 'x': 1, 'z': 3}
>>> dct["y"]
2
</code></pre>
<p>You can use variable key names to achieve the effect of variable variables without the secu... | 92 | 2009-09-03T12:41:05Z | [
"python",
"variable-variables"
] |
How do I create a variable number of variables in Python? | 1,373,164 | <p>How do I accomplish variable variables in Python? </p>
<p>Here is an elaborative manual entry, for instance: <em><a href="http://us3.php.net/manual/en/language.variables.variable.php">Variable variables</a></em></p>
<p>I have heard this is a bad idea in general though, and it is a security hole in Python. Is that ... | 96 | 2009-09-03T12:37:48Z | 1,373,192 | <p>Whenever you want to use variable variables, it's probably better to use a dictionary. So instead of writing</p>
<pre><code>$foo = "bar"
$$foo = "baz"
</code></pre>
<p>you write </p>
<pre><code>mydict = {}
foo = "bar"
mydict[foo] = "baz"
</code></pre>
<p>This way you won't accidentally overwrite previously exist... | 21 | 2009-09-03T12:42:00Z | [
"python",
"variable-variables"
] |
How do I create a variable number of variables in Python? | 1,373,164 | <p>How do I accomplish variable variables in Python? </p>
<p>Here is an elaborative manual entry, for instance: <em><a href="http://us3.php.net/manual/en/language.variables.variable.php">Variable variables</a></em></p>
<p>I have heard this is a bad idea in general though, and it is a security hole in Python. Is that ... | 96 | 2009-09-03T12:37:48Z | 1,373,198 | <p>Use the built-in <a href="http://docs.python.org/library/functions.html#getattr"><code>getattr</code></a> function to get an attribute on an object by name. Modify the name as needed.</p>
<pre><code>obj.spam = 'eggs'
name = 'spam'
getattr(obj, name) # returns 'eggs'
</code></pre>
| 38 | 2009-09-03T12:43:26Z | [
"python",
"variable-variables"
] |
How do I create a variable number of variables in Python? | 1,373,164 | <p>How do I accomplish variable variables in Python? </p>
<p>Here is an elaborative manual entry, for instance: <em><a href="http://us3.php.net/manual/en/language.variables.variable.php">Variable variables</a></em></p>
<p>I have heard this is a bad idea in general though, and it is a security hole in Python. Is that ... | 96 | 2009-09-03T12:37:48Z | 1,373,201 | <p>It's not a good idea. If you are accessing a global variable you can use <a href="http://docs.python.org/library/functions.html#globals">globals()</a>.</p>
<pre><code>>>> a = 10
>>> globals()['a']
10
</code></pre>
<p>If you want to access a variable in the local scope you can use <a href="http://... | 33 | 2009-09-03T12:43:49Z | [
"python",
"variable-variables"
] |
How do I create a variable number of variables in Python? | 1,373,164 | <p>How do I accomplish variable variables in Python? </p>
<p>Here is an elaborative manual entry, for instance: <em><a href="http://us3.php.net/manual/en/language.variables.variable.php">Variable variables</a></em></p>
<p>I have heard this is a bad idea in general though, and it is a security hole in Python. Is that ... | 96 | 2009-09-03T12:37:48Z | 37,725,113 | <p>The consensus is to use a dictionary for this - see the other answers. This is a good idea for most cases, however, there are many aspects arising from this:</p>
<ul>
<li>you'll yourself be responsible for this dictionary, including garbage collection (of in-dict variables) etc.</li>
<li>there's either no locality ... | 0 | 2016-06-09T11:47:06Z | [
"python",
"variable-variables"
] |
How do I create a variable number of variables in Python? | 1,373,164 | <p>How do I accomplish variable variables in Python? </p>
<p>Here is an elaborative manual entry, for instance: <em><a href="http://us3.php.net/manual/en/language.variables.variable.php">Variable variables</a></em></p>
<p>I have heard this is a bad idea in general though, and it is a security hole in Python. Is that ... | 96 | 2009-09-03T12:37:48Z | 37,725,729 | <p>You have to use <a href="https://docs.python.org/2/library/functions.html#globals" rel="nofollow">globals() built in method</a> to achieve that behaviour:</p>
<pre><code>def var_of_var(k, v):
globals()[k] = v
print variable_name # NameError: name 'variable_name' is not defined
some_name = 'variable_name'
glob... | 1 | 2016-06-09T12:14:11Z | [
"python",
"variable-variables"
] |
How do I create a variable number of variables in Python? | 1,373,164 | <p>How do I accomplish variable variables in Python? </p>
<p>Here is an elaborative manual entry, for instance: <em><a href="http://us3.php.net/manual/en/language.variables.variable.php">Variable variables</a></em></p>
<p>I have heard this is a bad idea in general though, and it is a security hole in Python. Is that ... | 96 | 2009-09-03T12:37:48Z | 37,971,967 | <p>Instead of a dictionary you can also use namedtuple from the collections module, which makes access easier.</p>
<p>for example:</p>
<pre><code>#using dictionary
variables = {}
variables["first"] = 34
variables["second"] = 45
print variables["first"], variables["second"]
#using namedtuple
Variables = namedtuple('V... | 3 | 2016-06-22T15:09:32Z | [
"python",
"variable-variables"
] |
How do I create a variable number of variables in Python? | 1,373,164 | <p>How do I accomplish variable variables in Python? </p>
<p>Here is an elaborative manual entry, for instance: <em><a href="http://us3.php.net/manual/en/language.variables.variable.php">Variable variables</a></em></p>
<p>I have heard this is a bad idea in general though, and it is a security hole in Python. Is that ... | 96 | 2009-09-03T12:37:48Z | 38,972,761 | <p>New coders sometimes write code like this:</p>
<pre><code>my_calculator.button_0 = tkinter.Button(root, text=0)
my_calculator.button_1 = tkinter.Button(root, text=1)
my_calculator.button_2 = tkinter.Button(root, text=2)
...
</code></pre>
<p>The coder is then left with a pile of named variables, with a coding effor... | 0 | 2016-08-16T10:41:07Z | [
"python",
"variable-variables"
] |
making python 2.6 exception backward compatible | 1,373,255 | <p>I have the following python code:</p>
<pre><code> try:
pr.update()
except ConfigurationException as e:
returnString=e.line+' '+e.errormsg
</code></pre>
<p>This works under python 2.6, but the "as e" syntax fails under previous versions. How can I resolved this? Or in other words, how do I catch user-d... | 7 | 2009-09-03T12:55:16Z | 1,373,261 | <p>This is backward compatible: </p>
<pre><code>try:
pr.update()
except ConfigurationException, e:
returnString=e.line+' '+e.errormsg
</code></pre>
| 9 | 2009-09-03T12:56:38Z | [
"python",
"exception",
"syntax",
"python-2.x"
] |
making python 2.6 exception backward compatible | 1,373,255 | <p>I have the following python code:</p>
<pre><code> try:
pr.update()
except ConfigurationException as e:
returnString=e.line+' '+e.errormsg
</code></pre>
<p>This works under python 2.6, but the "as e" syntax fails under previous versions. How can I resolved this? Or in other words, how do I catch user-d... | 7 | 2009-09-03T12:55:16Z | 1,373,263 | <pre><code>try:
pr.update()
except ConfigurationException, e:
returnString = e.line + " " + e.errormsg
</code></pre>
| 1 | 2009-09-03T12:56:58Z | [
"python",
"exception",
"syntax",
"python-2.x"
] |
making python 2.6 exception backward compatible | 1,373,255 | <p>I have the following python code:</p>
<pre><code> try:
pr.update()
except ConfigurationException as e:
returnString=e.line+' '+e.errormsg
</code></pre>
<p>This works under python 2.6, but the "as e" syntax fails under previous versions. How can I resolved this? Or in other words, how do I catch user-d... | 7 | 2009-09-03T12:55:16Z | 1,373,269 | <p>Read this: <a href="http://docs.python.org/reference/compound%5Fstmts.html#the-try-statement">http://docs.python.org/reference/compound%5Fstmts.html#the-try-statement</a></p>
<p>and this: <a href="http://docs.python.org/whatsnew/2.6.html#pep-3110-exception-handling-changes">http://docs.python.org/whatsnew/2.6.html#... | 5 | 2009-09-03T12:58:44Z | [
"python",
"exception",
"syntax",
"python-2.x"
] |
making python 2.6 exception backward compatible | 1,373,255 | <p>I have the following python code:</p>
<pre><code> try:
pr.update()
except ConfigurationException as e:
returnString=e.line+' '+e.errormsg
</code></pre>
<p>This works under python 2.6, but the "as e" syntax fails under previous versions. How can I resolved this? Or in other words, how do I catch user-d... | 7 | 2009-09-03T12:55:16Z | 2,513,890 | <p>This is both backward AND forward compatible:</p>
<pre><code>import sys
try:
pr.update()
except (ConfigurationException,):
e = sys.exc_info()[1]
returnString = "%s %s" % (e.line, e.errormsg)
</code></pre>
<p>This gets rid of the ambiguity problem in python 2.5 and earlier, while still not losing any of... | 12 | 2010-03-25T08:12:15Z | [
"python",
"exception",
"syntax",
"python-2.x"
] |
File open: Is this bad Python style? | 1,373,660 | <p>To read contents of a file:</p>
<pre><code>data = open(filename, "r").read()
</code></pre>
<p>The open file immediately stops being referenced anywhere, so the file object will eventually close... and it shouldn't affect other programs using it, since the file is only open for reading, not writing.</p>
<p>EDIT: T... | 10 | 2009-09-03T14:17:26Z | 1,373,672 | <p>No, it's perfectly reasonable Python style IMO, as per your reasoning.</p>
<p><strong>Update:</strong> There are a lot of comments here about whether file objects get tidied up straight away or not. Rather than speculate, I did some digging. Here's what I see:
<hr/>
From a comment in Python's <a href="http://svn.py... | 3 | 2009-09-03T14:19:17Z | [
"python",
"file",
"file-io",
"coding-style"
] |
File open: Is this bad Python style? | 1,373,660 | <p>To read contents of a file:</p>
<pre><code>data = open(filename, "r").read()
</code></pre>
<p>The open file immediately stops being referenced anywhere, so the file object will eventually close... and it shouldn't affect other programs using it, since the file is only open for reading, not writing.</p>
<p>EDIT: T... | 10 | 2009-09-03T14:17:26Z | 1,373,677 | <p>looks fine to me.. I read files like that often.</p>
| 1 | 2009-09-03T14:20:12Z | [
"python",
"file",
"file-io",
"coding-style"
] |
File open: Is this bad Python style? | 1,373,660 | <p>To read contents of a file:</p>
<pre><code>data = open(filename, "r").read()
</code></pre>
<p>The open file immediately stops being referenced anywhere, so the file object will eventually close... and it shouldn't affect other programs using it, since the file is only open for reading, not writing.</p>
<p>EDIT: T... | 10 | 2009-09-03T14:17:26Z | 1,373,690 | <p>It is true that it will close eventually, but eventually might not be soon enough. Especially if you're using this inside a loop, the system might run out of file handles before the GC gets to the file objects.</p>
| 6 | 2009-09-03T14:21:38Z | [
"python",
"file",
"file-io",
"coding-style"
] |
File open: Is this bad Python style? | 1,373,660 | <p>To read contents of a file:</p>
<pre><code>data = open(filename, "r").read()
</code></pre>
<p>The open file immediately stops being referenced anywhere, so the file object will eventually close... and it shouldn't affect other programs using it, since the file is only open for reading, not writing.</p>
<p>EDIT: T... | 10 | 2009-09-03T14:17:26Z | 1,373,713 | <p>Just for the record:
This is only slightly longer, and closes the file immediately:</p>
<pre><code>from __future__ import with_statement
with open(filename, "r") as f:
data = f.read()
</code></pre>
| 29 | 2009-09-03T14:24:50Z | [
"python",
"file",
"file-io",
"coding-style"
] |
File open: Is this bad Python style? | 1,373,660 | <p>To read contents of a file:</p>
<pre><code>data = open(filename, "r").read()
</code></pre>
<p>The open file immediately stops being referenced anywhere, so the file object will eventually close... and it shouldn't affect other programs using it, since the file is only open for reading, not writing.</p>
<p>EDIT: T... | 10 | 2009-09-03T14:17:26Z | 1,373,828 | <p>The code works exactly as you say it does, but it's bad style nevertheless. Your code relies on assumptions which may be true now, but won't always be true. It's not impossible that your code will be run in a situation where the file being opened and not close <em>does</em> matter. Is it really worth that risk ju... | 4 | 2009-09-03T14:40:49Z | [
"python",
"file",
"file-io",
"coding-style"
] |
File open: Is this bad Python style? | 1,373,660 | <p>To read contents of a file:</p>
<pre><code>data = open(filename, "r").read()
</code></pre>
<p>The open file immediately stops being referenced anywhere, so the file object will eventually close... and it shouldn't affect other programs using it, since the file is only open for reading, not writing.</p>
<p>EDIT: T... | 10 | 2009-09-03T14:17:26Z | 2,047,151 | <p>Even though it works as expected, I think it fails in two counts:</p>
<ol>
<li>Your code will not scale up seamlessly, because you are reading the entire file into memory, and this may or may not be necessarily what you want.</li>
<li>According to the Zen of Python (try <code>import this</code> in the Python prompt... | 2 | 2010-01-12T06:30:14Z | [
"python",
"file",
"file-io",
"coding-style"
] |
using soaplib to connect to remote SOAP server lacking definition | 1,373,738 | <p>I am looking at the soaplib python module (it comes with standard ubuntu 9.04). I have used xmlrpclib extensively in the last years but now I am curious about soap. writing servers with soaplib is acceptably easy, I assume writing clients should be even easier.</p>
<p>in my impatience I can't find a way to make u... | 2 | 2009-09-03T14:28:23Z | 1,394,011 | <p>If I understand your question correctly, you would like to generate client code for a given webservice without defining what methods etc are availible on that service in your own code directly? IE: you would like to introspect the service and generate client automatically.</p>
<p>If this is the case then the answe... | 1 | 2009-09-08T13:22:39Z | [
"python",
"soap",
"introspection"
] |
Benefit cost analysis libraries | 1,373,902 | <p>I was wondering if there are any opensource libraries that are geared towards transportation ben/cost analysis. </p>
<p>I currently use <a href="http://www.dot.ca.gov/hq/tpp/offices/ote/benefit%5Fcost/models/microbencost.html" rel="nofollow">microBENCOST</a> and would like to build my own solution. I'm most comfort... | 2 | 2009-09-03T14:53:00Z | 1,410,655 | <p>microBENCOST is purchased by the californian department of transport and really it seems a suitable tool. What is missing? If you need something particular that is not yet implemented, maybe you should consider to write your own. It's really difficult to find something better </p>
| 1 | 2009-09-11T12:48:12Z | [
"c++",
"python",
"transport",
"economics"
] |
Benefit cost analysis libraries | 1,373,902 | <p>I was wondering if there are any opensource libraries that are geared towards transportation ben/cost analysis. </p>
<p>I currently use <a href="http://www.dot.ca.gov/hq/tpp/offices/ote/benefit%5Fcost/models/microbencost.html" rel="nofollow">microBENCOST</a> and would like to build my own solution. I'm most comfort... | 2 | 2009-09-03T14:53:00Z | 1,425,624 | <p>I don't think there are any alternatives, considering MicroBENCOST appears to be a special project developed for the state of California, and transportation analysis is about as niche as it gets.</p>
<p>If you are going to build your own solution, you will probably want to look into the various math libraries avail... | 2 | 2009-09-15T07:16:21Z | [
"c++",
"python",
"transport",
"economics"
] |
Benefit cost analysis libraries | 1,373,902 | <p>I was wondering if there are any opensource libraries that are geared towards transportation ben/cost analysis. </p>
<p>I currently use <a href="http://www.dot.ca.gov/hq/tpp/offices/ote/benefit%5Fcost/models/microbencost.html" rel="nofollow">microBENCOST</a> and would like to build my own solution. I'm most comfort... | 2 | 2009-09-03T14:53:00Z | 1,430,169 | <p>My girlfriend works for a transportation planning firm, and they use a variety of models developed in SPSS, with a lot of data munging in Excel and visualization in ArcGIS. As far as turnkey solutions go, though, I think you're going to be more or less on your own.</p>
<p>Assuming you want to move on to something a... | 4 | 2009-09-15T23:34:19Z | [
"c++",
"python",
"transport",
"economics"
] |
On a Mac w/ Python2.6 and trying to install psycopg2 | 1,374,187 | <p>I am new to Python. I have Python2.6 running now. I am following the Tutorial on the Python site. My question is when I try to follow the instructions here:</p>
<p><a href="http://py-psycopg.darwinports.com/" rel="nofollow">http://py-psycopg.darwinports.com/</a></p>
<p>I get something like...</p>
<pre><code>sudo ... | 1 | 2009-09-03T15:34:31Z | 1,374,304 | <p>If you're using Python 2.6, you actually want to build <code>py26-psycopg2</code>:</p>
<pre><code>$ sudo port install py26-psycopg2
</code></pre>
<p>In MacPorts, <code>py-*</code> packages build using Python 2.4, <code>py25-*</code> using Python 2.5, and <code>py26-*</code> use Python 2.6.</p>
| 10 | 2009-09-03T15:54:39Z | [
"python",
"osx"
] |
On a Mac w/ Python2.6 and trying to install psycopg2 | 1,374,187 | <p>I am new to Python. I have Python2.6 running now. I am following the Tutorial on the Python site. My question is when I try to follow the instructions here:</p>
<p><a href="http://py-psycopg.darwinports.com/" rel="nofollow">http://py-psycopg.darwinports.com/</a></p>
<p>I get something like...</p>
<pre><code>sudo ... | 1 | 2009-09-03T15:34:31Z | 1,374,308 | <p>Maybe you need to look at the <a href="http://py26-psycopg2.darwinports.com/" rel="nofollow">version for Python 2.6</a>? </p>
| 3 | 2009-09-03T15:54:49Z | [
"python",
"osx"
] |
On a Mac w/ Python2.6 and trying to install psycopg2 | 1,374,187 | <p>I am new to Python. I have Python2.6 running now. I am following the Tutorial on the Python site. My question is when I try to follow the instructions here:</p>
<p><a href="http://py-psycopg.darwinports.com/" rel="nofollow">http://py-psycopg.darwinports.com/</a></p>
<p>I get something like...</p>
<pre><code>sudo ... | 1 | 2009-09-03T15:34:31Z | 1,374,645 | <p>I installed psycopg2 on my Mac with setuptools and easy_install. First get the Python 2.6 egg from the <a href="http://pypi.python.org/pypi/setuptools" rel="nofollow">setuptools downloads page</a>, then install it with the instructions on that page. Then you can run the following to install it:</p>
<pre><code>sudo... | 0 | 2009-09-03T16:51:13Z | [
"python",
"osx"
] |
On a Mac w/ Python2.6 and trying to install psycopg2 | 1,374,187 | <p>I am new to Python. I have Python2.6 running now. I am following the Tutorial on the Python site. My question is when I try to follow the instructions here:</p>
<p><a href="http://py-psycopg.darwinports.com/" rel="nofollow">http://py-psycopg.darwinports.com/</a></p>
<p>I get something like...</p>
<pre><code>sudo ... | 1 | 2009-09-03T15:34:31Z | 1,382,924 | <p>I had problems installing <code>psycopg2</code> on my 10.4 Mac too. I installed both Python and Postgres from dmg files, and <code>sudo easy_install psycopg2</code> was giving an error I can't remember now. What worked for me was an easy solution:</p>
<pre><code>PATH=$PATH:/Library/PostgreSQL/8.3/bin/ sudo easy_ins... | 1 | 2009-09-05T09:58:58Z | [
"python",
"osx"
] |
On a Mac w/ Python2.6 and trying to install psycopg2 | 1,374,187 | <p>I am new to Python. I have Python2.6 running now. I am following the Tutorial on the Python site. My question is when I try to follow the instructions here:</p>
<p><a href="http://py-psycopg.darwinports.com/" rel="nofollow">http://py-psycopg.darwinports.com/</a></p>
<p>I get something like...</p>
<pre><code>sudo ... | 1 | 2009-09-03T15:34:31Z | 1,622,533 | <p>I did this:</p>
<p><a href="http://tonylandis.com/python/installing-psycopg2-on-osx-105/" rel="nofollow">http://tonylandis.com/python/installing-psycopg2-on-osx-105/</a></p>
| 0 | 2009-10-25T23:54:27Z | [
"python",
"osx"
] |
On a Mac w/ Python2.6 and trying to install psycopg2 | 1,374,187 | <p>I am new to Python. I have Python2.6 running now. I am following the Tutorial on the Python site. My question is when I try to follow the instructions here:</p>
<p><a href="http://py-psycopg.darwinports.com/" rel="nofollow">http://py-psycopg.darwinports.com/</a></p>
<p>I get something like...</p>
<pre><code>sudo ... | 1 | 2009-09-03T15:34:31Z | 2,806,807 | <p>I tried everything and nothing works. At least this post:
<a href="http://benkreeger.com/post/312303245/conquering-symbol-not-found-pqbackendpid" rel="nofollow">http://benkreeger.com/post/312303245/conquering-symbol-not-found-pqbackendpid</a></p>
<p>led me to homebrew which made it perfectly.</p>
| 0 | 2010-05-10T22:10:36Z | [
"python",
"osx"
] |
How to add a namespace to an attribute in lxml | 1,374,443 | <p>I'm trying to create an xml entry that looks like this using python and lxml:</p>
<pre><code><resource href="Unit 4.html" adlcp:scormtype="sco">
</code></pre>
<p>I'm using python and lxml. I'm having trouble with the <code>adlcp:scormtype</code> attribute. I'm new to xml so please correct me if I'm wrong. ... | 7 | 2009-09-03T16:17:51Z | 1,374,757 | <p>This is not a full reply but just a few pointers.</p>
<p>adlcp is not the namespace it is a namespace prefix. The namespace is defined in the document by an attribute like <code>xmlns:adlcp="http://xxx/yy/zzz"</code></p>
<p>In lxml you always set an element/attribute name including the namespace e.g.
<code>{http:... | 14 | 2009-09-03T17:13:08Z | [
"python",
"xml",
"lxml",
"scorm"
] |
How to add a namespace to an attribute in lxml | 1,374,443 | <p>I'm trying to create an xml entry that looks like this using python and lxml:</p>
<pre><code><resource href="Unit 4.html" adlcp:scormtype="sco">
</code></pre>
<p>I'm using python and lxml. I'm having trouble with the <code>adlcp:scormtype</code> attribute. I'm new to xml so please correct me if I'm wrong. ... | 7 | 2009-09-03T16:17:51Z | 27,957,145 | <p>Try this:</p>
<pre><code>builder = ElementMaker(namespace="http://a.different.url/blah/v.10",
nsmap={
'adlcp': "http://a.namespace.url/blah/v.10",
'anotherns': "http://a.different.url/blah/v.10"
})
builder.resource()
bu... | 2 | 2015-01-15T05:07:50Z | [
"python",
"xml",
"lxml",
"scorm"
] |
Find out how many times a regex matches in a string in Python | 1,374,457 | <p>Is there a way that I can find out how many matches of a regex are in a string in Python? For example, if I have the string <code>"It actually happened when it acted out of turn."</code></p>
<p>I want to know how many times <code>"t a"</code> appears in the string. In that string, <code>"t a"</code> appears twice. ... | 15 | 2009-09-03T16:20:44Z | 1,374,469 | <p>Have you tried this?</p>
<pre><code> len( pattern.findall(source) )
</code></pre>
| 5 | 2009-09-03T16:22:10Z | [
"python",
"regex"
] |
Find out how many times a regex matches in a string in Python | 1,374,457 | <p>Is there a way that I can find out how many matches of a regex are in a string in Python? For example, if I have the string <code>"It actually happened when it acted out of turn."</code></p>
<p>I want to know how many times <code>"t a"</code> appears in the string. In that string, <code>"t a"</code> appears twice. ... | 15 | 2009-09-03T16:20:44Z | 1,374,471 | <pre><code>import re
len(re.findall(pattern, string_to_search))
</code></pre>
| 22 | 2009-09-03T16:22:47Z | [
"python",
"regex"
] |
Find out how many times a regex matches in a string in Python | 1,374,457 | <p>Is there a way that I can find out how many matches of a regex are in a string in Python? For example, if I have the string <code>"It actually happened when it acted out of turn."</code></p>
<p>I want to know how many times <code>"t a"</code> appears in the string. In that string, <code>"t a"</code> appears twice. ... | 15 | 2009-09-03T16:20:44Z | 1,374,488 | <pre><code>import re
print len(re.findall(r'ab',u'ababababa'))
</code></pre>
| 1 | 2009-09-03T16:26:10Z | [
"python",
"regex"
] |
Find out how many times a regex matches in a string in Python | 1,374,457 | <p>Is there a way that I can find out how many matches of a regex are in a string in Python? For example, if I have the string <code>"It actually happened when it acted out of turn."</code></p>
<p>I want to know how many times <code>"t a"</code> appears in the string. In that string, <code>"t a"</code> appears twice. ... | 15 | 2009-09-03T16:20:44Z | 1,374,516 | <p>I know this is a question about regex. I just thought I'd mention the <a href="http://docs.python.org/library/stdtypes.html#str.count">count</a> method for future reference if someone wants a non-regex solution.</p>
<pre><code>>>> s = "It actually happened when it acted out of turn."
>>> s.count('... | 7 | 2009-09-03T16:29:57Z | [
"python",
"regex"
] |
Find out how many times a regex matches in a string in Python | 1,374,457 | <p>Is there a way that I can find out how many matches of a regex are in a string in Python? For example, if I have the string <code>"It actually happened when it acted out of turn."</code></p>
<p>I want to know how many times <code>"t a"</code> appears in the string. In that string, <code>"t a"</code> appears twice. ... | 15 | 2009-09-03T16:20:44Z | 1,374,893 | <p>The existing solutions based on <code>findall</code> are fine for non-overlapping matches (and no doubt optimal except maybe for HUGE number of matches), although alternatives such as <code>sum(1 for m in re.finditer(thepattern, thestring))</code> (to avoid ever materializing the list when all you care about is the ... | 8 | 2009-09-03T17:43:59Z | [
"python",
"regex"
] |
Find out how many times a regex matches in a string in Python | 1,374,457 | <p>Is there a way that I can find out how many matches of a regex are in a string in Python? For example, if I have the string <code>"It actually happened when it acted out of turn."</code></p>
<p>I want to know how many times <code>"t a"</code> appears in the string. In that string, <code>"t a"</code> appears twice. ... | 15 | 2009-09-03T16:20:44Z | 1,375,160 | <p>You can find overlapping matches by using a noncapturing subpattern:</p>
<pre><code>def count_overlapping(pattern, string):
return len(re.findall("(?=%s)" % pattern, string))
</code></pre>
| 3 | 2009-09-03T18:32:48Z | [
"python",
"regex"
] |
Find out how many times a regex matches in a string in Python | 1,374,457 | <p>Is there a way that I can find out how many matches of a regex are in a string in Python? For example, if I have the string <code>"It actually happened when it acted out of turn."</code></p>
<p>I want to know how many times <code>"t a"</code> appears in the string. In that string, <code>"t a"</code> appears twice. ... | 15 | 2009-09-03T16:20:44Z | 5,634,958 | <p>To avoid creating a list of matches one may also use <a href="http://docs.python.org/library/re#re.sub" rel="nofollow">re.sub</a> with a callable as replacement. It will be called on each match, incrementing internal counter.</p>
<pre><code>class Counter(object):
def __init__(self):
self.matched = 0
... | 0 | 2011-04-12T12:10:33Z | [
"python",
"regex"
] |
save python output to log | 1,375,283 | <p>I have a python script the runs this code:</p>
<pre><code>strpath = "sudo svnadmin create /svn/repos/" + short_name
os.popen (strpath, 'w')
</code></pre>
<p>How can I get the output of that command stored in a variable or written to a log file in the current directory?</p>
<p>I know, there may not be an output, b... | 0 | 2009-09-03T18:56:56Z | 1,375,290 | <p>you can do it in your bash-part:</p>
<pre><code>strpath = "sudo svnadmin create /svn/repos/" + short_name + ' > log.txt'
</code></pre>
| 0 | 2009-09-03T18:58:59Z | [
"python",
"logging",
"variables"
] |
save python output to log | 1,375,283 | <p>I have a python script the runs this code:</p>
<pre><code>strpath = "sudo svnadmin create /svn/repos/" + short_name
os.popen (strpath, 'w')
</code></pre>
<p>How can I get the output of that command stored in a variable or written to a log file in the current directory?</p>
<p>I know, there may not be an output, b... | 0 | 2009-09-03T18:56:56Z | 1,375,292 | <p>If you don't need to write to the command, then just change the 'w' to 'r':</p>
<pre><code>strpath = "sudo svnadmin create /svn/repos/" + short_name
output = os.popen (strpath, 'r')
for line in output.readlines():
# do stuff
</code></pre>
<p>Alternatively if you don't want to process line-by-line:</p>
<pre><... | 1 | 2009-09-03T18:59:10Z | [
"python",
"logging",
"variables"
] |
save python output to log | 1,375,283 | <p>I have a python script the runs this code:</p>
<pre><code>strpath = "sudo svnadmin create /svn/repos/" + short_name
os.popen (strpath, 'w')
</code></pre>
<p>How can I get the output of that command stored in a variable or written to a log file in the current directory?</p>
<p>I know, there may not be an output, b... | 0 | 2009-09-03T18:56:56Z | 1,375,295 | <p>Use the <code>'r'</code> mode to open the pipe instead:</p>
<pre><code>f = os.popen (strpath, 'r')
for line in f:
print line
f.close()
</code></pre>
<p>See the documentation for <a href="http://docs.python.org/library/os.html#os.popen" rel="nofollow"><code>os.popen()</code></a> for more information.</p>
<p>Th... | 3 | 2009-09-03T19:00:56Z | [
"python",
"logging",
"variables"
] |
Wrapping Mutually Dependent Structs in Pyrex | 1,375,293 | <p>I am attempting to wrap some C code in Python using Pyrex. I've run into an issue with defining two structs. In this case, the structures have been defined in terms of one another, and Pyrex cannot seem to handle the conflict. The structures look something like so:</p>
<pre><code>typedef struct a {
b * b_poi... | 2 | 2009-09-03T19:00:20Z | 1,376,307 | <p>You can use an <a href="http://ldots.org/pyrex-guide/4-functions.html#incomplete%5Ftypes" rel="nofollow">incomplete type</a> (you do need the corresponding C typedefs in to be in a <code>.h</code> file, not just a <code>.c</code> file):</p>
<pre><code>cdef extern from "some.h":
ctypedef struct b
ctypedef struct... | 3 | 2009-09-03T22:28:19Z | [
"python",
"c",
"struct",
"wrapper"
] |
Error importing a python module in Django | 1,375,382 | <p>In my Django project, the following line throws an ImportError: "No module named elementtree".</p>
<pre><code> from elementtree import ElementTree
</code></pre>
<p>However, the module is installed (ie, I can run an interactive python shell, and type that exact line without any ImportError), and the directory cont... | 2 | 2009-09-03T19:17:47Z | 1,375,418 | <p>Go into your installation directory</p>
<p>Example: </p>
<blockquote>
<p>C:\Python26\Lib\site-packages</p>
</blockquote>
<p>And check if both elementtree and django are in there. </p>
<p>If they are both not there, then you probably have multiple installation directories for different versions of Python. </p>
... | 0 | 2009-09-03T19:25:18Z | [
"python",
"django",
"elementtree",
"python-module"
] |
Error importing a python module in Django | 1,375,382 | <p>In my Django project, the following line throws an ImportError: "No module named elementtree".</p>
<pre><code> from elementtree import ElementTree
</code></pre>
<p>However, the module is installed (ie, I can run an interactive python shell, and type that exact line without any ImportError), and the directory cont... | 2 | 2009-09-03T19:17:47Z | 1,375,562 | <p>I've also run into cross-platform issues where ElementTree was available from different modules on different systems... this ended up working for me:</p>
<pre><code>try:
import elementtree.ElementTree as ET
except:
import xml.etree.ElementTree as ET
</code></pre>
<p>May or may not help for you...</p>
| 1 | 2009-09-03T19:49:40Z | [
"python",
"django",
"elementtree",
"python-module"
] |
Error importing a python module in Django | 1,375,382 | <p>In my Django project, the following line throws an ImportError: "No module named elementtree".</p>
<pre><code> from elementtree import ElementTree
</code></pre>
<p>However, the module is installed (ie, I can run an interactive python shell, and type that exact line without any ImportError), and the directory cont... | 2 | 2009-09-03T19:17:47Z | 1,375,595 | <p>Can you import <code>elementtree</code> within the django shell:</p>
<pre><code>python manage.py shell
</code></pre>
<p>Assuming you have multiple python versions and do not know which one is being used to run your site, add the following to your view and push <code>python_ver</code> to your template, it will sho... | 4 | 2009-09-03T19:53:33Z | [
"python",
"django",
"elementtree",
"python-module"
] |
Problem with polling sockets in python | 1,375,772 | <p>After I begin the polling loop, all messages printed after the first iteration require me to press enter in the terminal for it to be displayed.</p>
<pre><code>#!/usr/bin/python
import socket, select, os, pty, sys
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 5007))
s.listen(5)
mypoll = select... | 0 | 2009-09-03T20:31:38Z | 1,375,888 | <p>After the first iteration, haven't you registered the pty fd, and are then polling it? And its fd will never be equal to the socket fd, so you will then os.read the pty fd. And isn't that now reading from your terminal? And so won't typing a return cause it to "print data"?</p>
| 1 | 2009-09-03T20:52:30Z | [
"python",
"sockets",
"fork",
"polling"
] |
How do create a python module for MySQL Workbench? | 1,375,881 | <p>I am trying to create a simple Python module for MySQL Workbench 5.1.17 SE however I cannot seem to register the module, that is, it is not displaying under the Plugins->Catalog menu. </p>
<p>The documentation appears to be rather weak at this time, the best I have found is <a href="http://mysqlworkbench.org/?p=197... | 0 | 2009-09-03T20:50:57Z | 1,376,968 | <p>I chatted with one of the developers of MySQL Workbench via IRC and it turns out there were two problems:</p>
<ol>
<li>I had to make sure my python script ended with *_grt.py so that it was recognized as a module.</li>
<li><p>There is a bug at least in version 5.1.17+ that prevents more than one python script modul... | 1 | 2009-09-04T02:37:36Z | [
"python",
"plugins",
"mysql-workbench"
] |
How to get the signed integer value of a long in python? | 1,375,897 | <p>If lv stores a long value, and the machine is 32 bits, the following code: </p>
<pre><code>iv = int(lv & 0xffffffff)
</code></pre>
<p>results an iv of type long, instead of the machine's int. </p>
<p>How can I get the (signed) int value in this case?</p>
| 12 | 2009-09-03T20:54:38Z | 1,375,939 | <p>You're working in a high-level scripting language; by nature, the native data types of the system you're running on aren't visible. You can't cast to a native signed int with code like this.</p>
<p>If you know that you want the value converted to a 32-bit signed integer--regardless of the platform--you can just do... | 12 | 2009-09-03T21:03:04Z | [
"python",
"unsigned",
"signed"
] |
How to get the signed integer value of a long in python? | 1,375,897 | <p>If lv stores a long value, and the machine is 32 bits, the following code: </p>
<pre><code>iv = int(lv & 0xffffffff)
</code></pre>
<p>results an iv of type long, instead of the machine's int. </p>
<p>How can I get the (signed) int value in this case?</p>
| 12 | 2009-09-03T20:54:38Z | 1,390,179 | <p>You may use <strong>struct</strong> library to convert values like that. It's ugly, but works:</p>
<pre><code>from struct import pack, unpack
signed = unpack('l', pack('L', lv & 0xffffffff))[0]
</code></pre>
| 6 | 2009-09-07T16:53:49Z | [
"python",
"unsigned",
"signed"
] |
How to get the signed integer value of a long in python? | 1,375,897 | <p>If lv stores a long value, and the machine is 32 bits, the following code: </p>
<pre><code>iv = int(lv & 0xffffffff)
</code></pre>
<p>results an iv of type long, instead of the machine's int. </p>
<p>How can I get the (signed) int value in this case?</p>
| 12 | 2009-09-03T20:54:38Z | 9,351,268 | <pre><code>import ctypes
number = lv & 0xFFFFFFFF
signed_number = ctypes.c_long(number).value
</code></pre>
| 13 | 2012-02-19T17:13:34Z | [
"python",
"unsigned",
"signed"
] |
How to get the signed integer value of a long in python? | 1,375,897 | <p>If lv stores a long value, and the machine is 32 bits, the following code: </p>
<pre><code>iv = int(lv & 0xffffffff)
</code></pre>
<p>results an iv of type long, instead of the machine's int. </p>
<p>How can I get the (signed) int value in this case?</p>
| 12 | 2009-09-03T20:54:38Z | 11,612,456 | <p>Can I suggest this:</p>
<pre><code>def getSignedNumber(number, bitLength):
mask = (2 ** bitLength) - 1
if number & (1 << (bitLength - 1)):
return number | ~mask
else:
return number & mask
print iv, '->', getSignedNumber(iv, 32)
</code></pre>
| 4 | 2012-07-23T12:22:44Z | [
"python",
"unsigned",
"signed"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.