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 |
|---|---|---|---|---|---|---|---|---|---|
What to write into log file? | 779,989 | <p>My question is simple: what to write into a log.
Are there any conventions?
What do I have to put in?</p>
<p>Since my app has to be released, I'd like to have friendly logs, which could be read by most people without asking what it is.</p>
<p>I already have some ideas, like a timestamp, a unique identifier for eac... | 10 | 2009-04-23T01:41:25Z | 780,829 | <p>In my opinion, best approach is to use existing logging libraries such as <a href="http://logging.apache.org/" rel="nofollow">log4j (or it's variations for other languages)</a>. It gives you control on how your messages are formatted and you can change it without ever touching your code. It follows best practices, r... | 1 | 2009-04-23T08:48:56Z | [
"python",
"logging",
"methodology"
] |
What to write into log file? | 779,989 | <p>My question is simple: what to write into a log.
Are there any conventions?
What do I have to put in?</p>
<p>Since my app has to be released, I'd like to have friendly logs, which could be read by most people without asking what it is.</p>
<p>I already have some ideas, like a timestamp, a unique identifier for eac... | 10 | 2009-04-23T01:41:25Z | 2,043,176 | <p>Python's logging library are thread-safe for single process threads.</p>
| 0 | 2010-01-11T16:31:06Z | [
"python",
"logging",
"methodology"
] |
how get last number in range in python | 780,057 | <p>there is a way to get the last number <strong>in range</strong> i need to get the last number in fibonacci sequence for first 20 terms or can to do with a list instead range?</p>
| 0 | 2009-04-23T02:13:42Z | 780,063 | <p>Is this what you're after?</p>
<pre><code>somerange = range(0,20)
print len(somerange) # if you want 20
print len(somerange)-1 # if you want 19
</code></pre>
<p>now if you want the number or item contained in a list...</p>
<pre><code>x = [1,2,3,4]
print x[len(x)-1]
# OR
print x[-1] # go back 1 element from curren... | 0 | 2009-04-23T02:16:05Z | [
"python",
"range",
"fibonacci"
] |
how get last number in range in python | 780,057 | <p>there is a way to get the last number <strong>in range</strong> i need to get the last number in fibonacci sequence for first 20 terms or can to do with a list instead range?</p>
| 0 | 2009-04-23T02:13:42Z | 780,075 | <p>Not quite sure what you are after here but here goes:</p>
<pre><code>rangeList = range(0,21)
lastNumber = rangeList[len(rangeList)-1:][0]
</code></pre>
<p>or:</p>
<pre><code>lastNumber = rangeList[-1]
</code></pre>
| 4 | 2009-04-23T02:20:11Z | [
"python",
"range",
"fibonacci"
] |
how get last number in range in python | 780,057 | <p>there is a way to get the last number <strong>in range</strong> i need to get the last number in fibonacci sequence for first 20 terms or can to do with a list instead range?</p>
| 0 | 2009-04-23T02:13:42Z | 780,079 | <p>by <em>in a range</em>, do you mean last value provided by a generator? If so, you can do something like this:</p>
<pre><code>def fibonacci(iterations):
# generate your fibonacci numbers here...
[x for x in fibonacci(20)][-1]
</code></pre>
<p>That would get you the last generated value.</p>
| 2 | 2009-04-23T02:21:27Z | [
"python",
"range",
"fibonacci"
] |
how get last number in range in python | 780,057 | <p>there is a way to get the last number <strong>in range</strong> i need to get the last number in fibonacci sequence for first 20 terms or can to do with a list instead range?</p>
| 0 | 2009-04-23T02:13:42Z | 780,087 | <p>I don't think anyone considered that you need fibonacci numbers. No, you'll have to store each number to build the fibonacci sequence recursively, but there is a formula to get the nth term of the fibonacci sequence. </p>
<p><a href="http://mathworld.wolfram.com/BinetsFibonacciNumberFormula.html" rel="nofollow">Bi... | 1 | 2009-04-23T02:25:33Z | [
"python",
"range",
"fibonacci"
] |
Installing bitarray in Python 2.6 on Windows | 780,127 | <p>I would like to install <a href="http://pypi.python.org/pypi/bitarray/" rel="nofollow">bitarray</a> in Windows running python 2.6.</p>
<p>I have mingw32 installed, and I have <code>C:\Python26\Lib\distutils\distutils.cfg</code> set to:</p>
<pre><code>[build]
compiler = mingw32
</code></pre>
<p>If I type, in a <co... | 0 | 2009-04-23T02:48:41Z | 780,613 | <p>MingW cannot compile the bitarray sources, I tried with version 3.4.5 and get the same errors.
However, it compiles fine with the Microsoft compiler.</p>
<p>For your convenience I've build msi and exe installers for Python 2.6:</p>
<p><a href="http://starship.python.net/crew/theller/bitarray-0.3.5.win32-py2.6.msi"... | 3 | 2009-04-23T07:11:03Z | [
"python",
"c",
"mingw",
"bitarray"
] |
Installing bitarray in Python 2.6 on Windows | 780,127 | <p>I would like to install <a href="http://pypi.python.org/pypi/bitarray/" rel="nofollow">bitarray</a> in Windows running python 2.6.</p>
<p>I have mingw32 installed, and I have <code>C:\Python26\Lib\distutils\distutils.cfg</code> set to:</p>
<pre><code>[build]
compiler = mingw32
</code></pre>
<p>If I type, in a <co... | 0 | 2009-04-23T02:48:41Z | 2,305,630 | <p>I needed to build bitarray for myself (I needed bit shift), so I couldn't use your pre-built binaries. The problem lies in mingw not working properly with __declspec(dllimport). Python already solves this problem for cygwin builds by using auto-import instead of declspec. However, this is not enabled for mingw build... | 0 | 2010-02-21T10:55:46Z | [
"python",
"c",
"mingw",
"bitarray"
] |
How do I create collision detections for my bouncing balls? | 780,169 | <p>I have coded an animation (in python) for three beach balls to bounce around a screen. I now wish to have them all collide and be able to bounce off each other. I would really appreciate any help that can be offered.</p>
<pre><code>import pygame
import random
import sys
class Ball:
def __init__(self,X,Y):
... | 6 | 2009-04-23T03:13:56Z | 780,201 | <p>Collision detection for arbitrary shapes is usually quite tricky since you have to figure out if any pixel collides.</p>
<p>This is actually easier with circles. If you have two circles of radius r1 and r2, a collision has occurred if the distance between the centers is less than r1+r2.</p>
<p>The distance between... | 9 | 2009-04-23T03:29:34Z | [
"python",
"collision-detection"
] |
How do I create collision detections for my bouncing balls? | 780,169 | <p>I have coded an animation (in python) for three beach balls to bounce around a screen. I now wish to have them all collide and be able to bounce off each other. I would really appreciate any help that can be offered.</p>
<pre><code>import pygame
import random
import sys
class Ball:
def __init__(self,X,Y):
... | 6 | 2009-04-23T03:13:56Z | 780,226 | <p>Detecting collisions was covered well by <a href="http://stackoverflow.com/questions/780169/how-do-i-create-collision-detections-for-my-bouncing-balls/780201#780201">Pax's answer</a>. With respect to having objects bounce off one another, I suggest checking out the following links concerning <a href="http://en.wikip... | 1 | 2009-04-23T03:44:19Z | [
"python",
"collision-detection"
] |
How do I create collision detections for my bouncing balls? | 780,169 | <p>I have coded an animation (in python) for three beach balls to bounce around a screen. I now wish to have them all collide and be able to bounce off each other. I would really appreciate any help that can be offered.</p>
<pre><code>import pygame
import random
import sys
class Ball:
def __init__(self,X,Y):
... | 6 | 2009-04-23T03:13:56Z | 780,240 | <p>Detecting a collision is only the first step. Let's break that down.</p>
<p>The fastest thing to do is calculate their square bounding boxes and see if those collide. Two of the sides need to cross (top of 1 and bottom or 2, and left of 1 and right of 2, or vice versa) in order for the bounding boxes to overlap. No... | 3 | 2009-04-23T03:49:51Z | [
"python",
"collision-detection"
] |
How do I create collision detections for my bouncing balls? | 780,169 | <p>I have coded an animation (in python) for three beach balls to bounce around a screen. I now wish to have them all collide and be able to bounce off each other. I would really appreciate any help that can be offered.</p>
<pre><code>import pygame
import random
import sys
class Ball:
def __init__(self,X,Y):
... | 6 | 2009-04-23T03:13:56Z | 780,321 | <p>I think there is somehthing simpler that you guys are missing espeically considering he's using pygame.</p>
<p>Calling the <code>get_rect</code> function can set probably boundraies for the images and <code>Rect</code> that is created, is used for calculating the position of the image and if there are more than one... | 1 | 2009-04-23T04:30:17Z | [
"python",
"collision-detection"
] |
How do I create collision detections for my bouncing balls? | 780,169 | <p>I have coded an animation (in python) for three beach balls to bounce around a screen. I now wish to have them all collide and be able to bounce off each other. I would really appreciate any help that can be offered.</p>
<pre><code>import pygame
import random
import sys
class Ball:
def __init__(self,X,Y):
... | 6 | 2009-04-23T03:13:56Z | 782,683 | <p>Back in the good old times when CPU cycles were a premium coders used a simple trick to detect collision: they used such colours that they could tell from the pixel colour if it was background or an object. This was done on at least some C64 games.</p>
<p>Don't know if you are willing to go this route, though..</p>... | 0 | 2009-04-23T17:08:29Z | [
"python",
"collision-detection"
] |
How do I create collision detections for my bouncing balls? | 780,169 | <p>I have coded an animation (in python) for three beach balls to bounce around a screen. I now wish to have them all collide and be able to bounce off each other. I would really appreciate any help that can be offered.</p>
<pre><code>import pygame
import random
import sys
class Ball:
def __init__(self,X,Y):
... | 6 | 2009-04-23T03:13:56Z | 1,140,987 | <p>First you need to check collision with <code>rect.colliderect(other_rect)</code></p>
<p>after that if they are colliding, you can check pixel perfect collision. So you don't mess with object's radius or shape.</p>
<p>For pixel perfect collision checking, I use Masks:
Make both mask objects with <code>mask.from_sur... | 0 | 2009-07-17T00:31:55Z | [
"python",
"collision-detection"
] |
How do I create collision detections for my bouncing balls? | 780,169 | <p>I have coded an animation (in python) for three beach balls to bounce around a screen. I now wish to have them all collide and be able to bounce off each other. I would really appreciate any help that can be offered.</p>
<pre><code>import pygame
import random
import sys
class Ball:
def __init__(self,X,Y):
... | 6 | 2009-04-23T03:13:56Z | 39,060,229 | <p>I made a python collision detection if statement, here it is: </p>
<pre><code>if beach ball 1 x < beach ball 2 x + beach ball 1 width and beach ball 1 x + beach ball 2 width > beach ball 2 x and beach ball 1 y < beach ball 2 y + beach ball 1 height and beach ball 2 height + beach ball 1 y > beach ball 2... | 0 | 2016-08-21T02:02:06Z | [
"python",
"collision-detection"
] |
Unescape Python Strings From HTTP | 780,334 | <p>I've got a string from an HTTP header, but it's been escaped.. what function can I use to unescape it?</p>
<pre><code>myemail%40gmail.com -> myemail@gmail.com
</code></pre>
<p>Would urllib.unquote() be the way to go?</p>
| 14 | 2009-04-23T04:36:55Z | 780,344 | <p>I am pretty sure that urllib's <a href="http://docs.python.org/library/urllib.html#urllib.unquote"><code>unquote</code></a> is the common way of doing this.</p>
<pre><code>>>> import urllib
>>> urllib.unquote("myemail%40gmail.com")
'myemail@gmail.com'
</code></pre>
<p>There's also <a href="http:/... | 33 | 2009-04-23T04:41:14Z | [
"python",
"http",
"header",
"urllib2",
"mod-wsgi"
] |
Unescape Python Strings From HTTP | 780,334 | <p>I've got a string from an HTTP header, but it's been escaped.. what function can I use to unescape it?</p>
<pre><code>myemail%40gmail.com -> myemail@gmail.com
</code></pre>
<p>Would urllib.unquote() be the way to go?</p>
| 14 | 2009-04-23T04:36:55Z | 780,350 | <p>Yes, it appears that <a href="http://docs.python.org/library/urllib.html#urllib.unquote" rel="nofollow"><code>urllib.unquote()</code></a> accomplishes that task. (I <a href="http://codepad.org/SerdBuAK" rel="nofollow">tested it against your example on codepad</a>.)</p>
| 2 | 2009-04-23T04:42:59Z | [
"python",
"http",
"header",
"urllib2",
"mod-wsgi"
] |
Unescape Python Strings From HTTP | 780,334 | <p>I've got a string from an HTTP header, but it's been escaped.. what function can I use to unescape it?</p>
<pre><code>myemail%40gmail.com -> myemail@gmail.com
</code></pre>
<p>Would urllib.unquote() be the way to go?</p>
| 14 | 2009-04-23T04:36:55Z | 28,435,067 | <p>In Python 3, these functions are <a href="https://docs.python.org/3.4/library/urllib.parse.html#urllib.parse.unquote" rel="nofollow"><code>urllib.parse.unquote</code></a> and <a href="https://docs.python.org/3.4/library/urllib.parse.html#urllib.parse.unquote" rel="nofollow"><code>urllib.parse.unquote_plus</code></a>... | 0 | 2015-02-10T15:09:14Z | [
"python",
"http",
"header",
"urllib2",
"mod-wsgi"
] |
Convert a number to a list of integers | 780,390 | <p>How do I write the <code>magic</code> function below?</p>
<pre><code>>>> num = 123
>>> lst = magic(num)
>>>
>>> print lst, type(lst)
[1, 2, 3], <type 'list'>
</code></pre>
| 13 | 2009-04-23T05:14:20Z | 780,403 | <p>You mean this?</p>
<pre><code>num = 1234
lst = [int(i) for i in str(num)]
</code></pre>
| 47 | 2009-04-23T05:22:12Z | [
"python",
"list",
"integer"
] |
Convert a number to a list of integers | 780,390 | <p>How do I write the <code>magic</code> function below?</p>
<pre><code>>>> num = 123
>>> lst = magic(num)
>>>
>>> print lst, type(lst)
[1, 2, 3], <type 'list'>
</code></pre>
| 13 | 2009-04-23T05:14:20Z | 780,407 | <p>You could do this:</p>
<pre><code>>>> num = 123
>>> lst = map(int, str(num))
>>> lst, type(lst)
([1, 2, 3], <type 'list'>)
</code></pre>
| 10 | 2009-04-23T05:23:15Z | [
"python",
"list",
"integer"
] |
Convert a number to a list of integers | 780,390 | <p>How do I write the <code>magic</code> function below?</p>
<pre><code>>>> num = 123
>>> lst = magic(num)
>>>
>>> print lst, type(lst)
[1, 2, 3], <type 'list'>
</code></pre>
| 13 | 2009-04-23T05:14:20Z | 780,409 | <pre><code>a = 123456
b = str(a)
c = []
for digit in b:
c.append (int(digit))
print c
</code></pre>
| 6 | 2009-04-23T05:26:02Z | [
"python",
"list",
"integer"
] |
Convert a number to a list of integers | 780,390 | <p>How do I write the <code>magic</code> function below?</p>
<pre><code>>>> num = 123
>>> lst = magic(num)
>>>
>>> print lst, type(lst)
[1, 2, 3], <type 'list'>
</code></pre>
| 13 | 2009-04-23T05:14:20Z | 780,433 | <p>Don't use the word <em>list</em> as variable name! It is a name of python built in data type.</p>
<p>Also, please clarify your question. If you are looking for a way to create a one-member list, do the following:</p>
<pre><code>a = 123
my_list = [a]
</code></pre>
<p>and "pythonizing" Cannonade's answer:</p>
<pre... | 5 | 2009-04-23T05:48:21Z | [
"python",
"list",
"integer"
] |
Convert a number to a list of integers | 780,390 | <p>How do I write the <code>magic</code> function below?</p>
<pre><code>>>> num = 123
>>> lst = magic(num)
>>>
>>> print lst, type(lst)
[1, 2, 3], <type 'list'>
</code></pre>
| 13 | 2009-04-23T05:14:20Z | 780,484 | <pre><code>magic = lambda num: map(int, str(num))
</code></pre>
<p>then just do</p>
<pre><code>magic(12345)
</code></pre>
<p>or </p>
<pre><code>magic(someInt) #or whatever
</code></pre>
| 6 | 2009-04-23T06:19:11Z | [
"python",
"list",
"integer"
] |
Convert a number to a list of integers | 780,390 | <p>How do I write the <code>magic</code> function below?</p>
<pre><code>>>> num = 123
>>> lst = magic(num)
>>>
>>> print lst, type(lst)
[1, 2, 3], <type 'list'>
</code></pre>
| 13 | 2009-04-23T05:14:20Z | 10,471,209 | <p>Just use : </p>
<pre><code>a= str (num)
lst = list(a)
</code></pre>
| 1 | 2012-05-06T14:16:33Z | [
"python",
"list",
"integer"
] |
Convert a number to a list of integers | 780,390 | <p>How do I write the <code>magic</code> function below?</p>
<pre><code>>>> num = 123
>>> lst = magic(num)
>>>
>>> print lst, type(lst)
[1, 2, 3], <type 'list'>
</code></pre>
| 13 | 2009-04-23T05:14:20Z | 10,471,766 | <pre><code>>>> from collections import deque
>>> def magic(num):
digits = deque()
while True:
num,r = divmod(num,10)
digits.appendleft(r)
if num == 0:
break
return list(digits)
>>> magic(123)
[1, 2, 3]
</code></pre>
... | 5 | 2012-05-06T15:31:04Z | [
"python",
"list",
"integer"
] |
Convert a number to a list of integers | 780,390 | <p>How do I write the <code>magic</code> function below?</p>
<pre><code>>>> num = 123
>>> lst = magic(num)
>>>
>>> print lst, type(lst)
[1, 2, 3], <type 'list'>
</code></pre>
| 13 | 2009-04-23T05:14:20Z | 28,144,400 | <pre><code>num = map(int, list(str(num)))
</code></pre>
| 0 | 2015-01-26T03:24:05Z | [
"python",
"list",
"integer"
] |
Convert a number to a list of integers | 780,390 | <p>How do I write the <code>magic</code> function below?</p>
<pre><code>>>> num = 123
>>> lst = magic(num)
>>>
>>> print lst, type(lst)
[1, 2, 3], <type 'list'>
</code></pre>
| 13 | 2009-04-23T05:14:20Z | 35,940,131 | <p>If it is named as magic, why not just use magic:</p>
<pre><code>def magic(x):
if x < 10:
return [x]
else:
return magic(x//10) + [x%10]
</code></pre>
| 0 | 2016-03-11T12:19:18Z | [
"python",
"list",
"integer"
] |
How to automatically reload a python file when it is changed | 780,526 | <p>If I make some changes to one of the files belonging to a running app, is there a way to tell the python runtime to automatically reload the module/file?</p>
<p>Cheers
Naren</p>
| 8 | 2009-04-23T06:40:03Z | 780,624 | <p>Here is a very old module that I posted nearly ten years ago. I may no longer work with current Python versions (I have not checked) but it may give some ideas.</p>
<p><a href="http://mail.python.org/pipermail/python-list/2000-April/031568.html" rel="nofollow">http://mail.python.org/pipermail/python-list/2000-Apri... | 4 | 2009-04-23T07:15:02Z | [
"python"
] |
How to automatically reload a python file when it is changed | 780,526 | <p>If I make some changes to one of the files belonging to a running app, is there a way to tell the python runtime to automatically reload the module/file?</p>
<p>Cheers
Naren</p>
| 8 | 2009-04-23T06:40:03Z | 780,698 | <p>Take look at <a href="http://code.djangoproject.com/svn/django/trunk/django/utils/autoreload.py" rel="nofollow">Django's autoreload module</a>. It works very well.</p>
| 4 | 2009-04-23T07:42:43Z | [
"python"
] |
How to automatically reload a python file when it is changed | 780,526 | <p>If I make some changes to one of the files belonging to a running app, is there a way to tell the python runtime to automatically reload the module/file?</p>
<p>Cheers
Naren</p>
| 8 | 2009-04-23T06:40:03Z | 780,769 | <p>Take at look at <a href="http://www.cherrypy.org/attachment/wiki/AutoReload/autoreload.py" rel="nofollow" rel="nofollow">CherryPy's Autoreload feature</a>. I think it looks quite simple and always worked well for me.</p>
| 5 | 2009-04-23T08:16:30Z | [
"python"
] |
Python base class method call: unexpected behavior | 780,670 | <p>Why does <code>str(A())</code> seemingly call <code>A.__repr__()</code> and not <code>dict.__str__()</code> in the example below?</p>
<pre><code>class A(dict):
def __repr__(self):
return 'repr(A)'
def __str__(self):
return dict.__str__(self)
class B(dict):
def __str__(self):
ret... | 5 | 2009-04-23T07:31:02Z | 780,728 | <p><code>str(A())</code> does call <code>__str__</code>, in turn calling <code>dict.__str__()</code>. </p>
<p>It is <code>dict.__str__()</code> that returns the value repr(A).</p>
| 9 | 2009-04-23T07:58:52Z | [
"python",
"inheritance",
"dictionary"
] |
Python base class method call: unexpected behavior | 780,670 | <p>Why does <code>str(A())</code> seemingly call <code>A.__repr__()</code> and not <code>dict.__str__()</code> in the example below?</p>
<pre><code>class A(dict):
def __repr__(self):
return 'repr(A)'
def __str__(self):
return dict.__str__(self)
class B(dict):
def __str__(self):
ret... | 5 | 2009-04-23T07:31:02Z | 780,765 | <p>I have modified the code to clear things out:</p>
<pre><code>class A(dict):
def __repr__(self):
print "repr of A called",
return 'repr(A)'
def __str__(self):
print "str of A called",
return dict.__str__(self)
class B(dict):
def __str__(self):
print "str of B called",
re... | 3 | 2009-04-23T08:14:37Z | [
"python",
"inheritance",
"dictionary"
] |
Python base class method call: unexpected behavior | 780,670 | <p>Why does <code>str(A())</code> seemingly call <code>A.__repr__()</code> and not <code>dict.__str__()</code> in the example below?</p>
<pre><code>class A(dict):
def __repr__(self):
return 'repr(A)'
def __str__(self):
return dict.__str__(self)
class B(dict):
def __str__(self):
ret... | 5 | 2009-04-23T07:31:02Z | 1,659,474 | <p>I have posted a workaround solution to it. Check it out ... you might find it useful:
<a href="http://blog.teltub.com/2009/10/workaround-solution-to-python-strrepr.html" rel="nofollow">http://blog.teltub.com/2009/10/workaround-solution-to-python-strrepr.html</a></p>
<p>P.S. Read the original post where I introduced... | 2 | 2009-11-02T04:58:58Z | [
"python",
"inheritance",
"dictionary"
] |
Playing and controlling mp3 files in Python? | 780,711 | <p>First things first, I am a Python beginner, with a typical C++/Java background for object oriented stuff.</p>
<p>I was convinced to try Python for this current endeavor I am working on, and so far I like it. One issue I am having though is finding a good mp3 module.</p>
<p>I have tried TkSnack, which installed and... | 4 | 2009-04-23T07:49:49Z | 780,757 | <p>Sorry I can't help you with PyMad or pyMedia, but I have other suggestions.</p>
<p>Existing music players written in Python:</p>
<ul>
<li><a href="http://www.exaile.org/" rel="nofollow">Exaile</a></li>
<li><a href="http://fuplayer.org/" rel="nofollow">FUPlayer</a></li>
<li><a href="http://listengnome.free.fr/" rel... | 2 | 2009-04-23T08:09:34Z | [
"python",
"audio",
"mp3",
"audio-streaming"
] |
Playing and controlling mp3 files in Python? | 780,711 | <p>First things first, I am a Python beginner, with a typical C++/Java background for object oriented stuff.</p>
<p>I was convinced to try Python for this current endeavor I am working on, and so far I like it. One issue I am having though is finding a good mp3 module.</p>
<p>I have tried TkSnack, which installed and... | 4 | 2009-04-23T07:49:49Z | 781,853 | <p>I just had to deal with this, and from my research I think your best bets are <a href="http://www.pyglet.org" rel="nofollow">pyglet</a> and <a href="http://www.pygame.org" rel="nofollow">pygame</a>. They're interface packages with built-in a/v support.</p>
| 0 | 2009-04-23T14:00:03Z | [
"python",
"audio",
"mp3",
"audio-streaming"
] |
SQLAlchemy - Dictionary of tags | 780,774 | <p>I have question regarding the SQLAlchemy. How can I add into my mapped class the dictionary-like attribute, which maps the string keys into string values and which will be stored in the database (in the same or another table as original mapped object). I want this add support for arbitrary tags of my objects.</p>
<... | 14 | 2009-04-23T08:19:36Z | 781,137 | <p>The simple answer is 'no'.</p>
<p>SQLAlchemy is wrapper on a SQL database.</p>
<p>The relation examples you quote translate a relationship between SQL tables into a Python map-like structure to make it slightly simpler to do the SQL SELECT statements and locate rows in another table.</p>
<p>The </p>
<pre><code>i... | -5 | 2009-04-23T10:25:39Z | [
"python",
"sqlalchemy"
] |
SQLAlchemy - Dictionary of tags | 780,774 | <p>I have question regarding the SQLAlchemy. How can I add into my mapped class the dictionary-like attribute, which maps the string keys into string values and which will be stored in the database (in the same or another table as original mapped object). I want this add support for arbitrary tags of my objects.</p>
<... | 14 | 2009-04-23T08:19:36Z | 784,095 | <p>The simple answer is <strong>yes</strong>.</p>
<p>Just use an association proxy:</p>
<pre><code>from sqlalchemy import Column, Integer, String, Table, create_engine
from sqlalchemy import orm, MetaData, Column, ForeignKey
from sqlalchemy.orm import relation, mapper, sessionmaker
from sqlalchemy.orm.collections imp... | 21 | 2009-04-24T00:21:28Z | [
"python",
"sqlalchemy"
] |
How to set correct value for Django ROOT_URLCONF setting in different branches | 781,211 | <p>I've put site directory created by <code>django-admin startproject</code> under version control (Mercurial). Let's say, the site is called <code>frobnicator</code>.</p>
<p>Now I want to make some serious refactoring, so I clone the site using command</p>
<pre><code>hg clone frobnicator frobnicator-refactoring`
</c... | 7 | 2009-04-23T10:54:32Z | 781,404 | <p>Simply remove project name form <code>ROOT_URLCONF</code> definition - it is optional. Then you can have project folder with different names.</p>
| 13 | 2009-04-23T12:01:26Z | [
"python",
"django",
"mercurial"
] |
CSS parser + XHTML generator, advice needed | 781,382 | <p>Guys, I need to develop a tool which would meet following requirements:</p>
<ol>
<li>Input: XHTML document with CSS rules within <code>head</code> section. </li>
<li>Output: XHTML document with CSS rules computed in tag attributes</li>
</ol>
<p>The best way to illustrate the behavior I want is as follows.</p>
<p... | 5 | 2009-04-23T11:53:09Z | 782,055 | <p>Depends on how complicated your CSS is going to be. If it's a simple matter of elements ("p {}", "a {}"), IDs/Classes (#test {}), then probably easiest to use regular expressions. You'd have to have one to find all the style definitions and then parse them, then use more regular expressions to find instances of ta... | 0 | 2009-04-23T14:38:25Z | [
"python",
"css",
"parsing",
"xhtml"
] |
CSS parser + XHTML generator, advice needed | 781,382 | <p>Guys, I need to develop a tool which would meet following requirements:</p>
<ol>
<li>Input: XHTML document with CSS rules within <code>head</code> section. </li>
<li>Output: XHTML document with CSS rules computed in tag attributes</li>
</ol>
<p>The best way to illustrate the behavior I want is as follows.</p>
<p... | 5 | 2009-04-23T11:53:09Z | 782,094 | <p>Try premailer</p>
<p><a href="http://code.dunae.ca/premailer.web/" rel="nofollow">code.dunae.ca/premailer.web</a></p>
<p>More info:
<a href="http://www.campaignmonitor.com/blog/post/2455/automatically-generate-inline/" rel="nofollow">campaignmonitor.com</a></p>
| 3 | 2009-04-23T14:48:14Z | [
"python",
"css",
"parsing",
"xhtml"
] |
CSS parser + XHTML generator, advice needed | 781,382 | <p>Guys, I need to develop a tool which would meet following requirements:</p>
<ol>
<li>Input: XHTML document with CSS rules within <code>head</code> section. </li>
<li>Output: XHTML document with CSS rules computed in tag attributes</li>
</ol>
<p>The best way to illustrate the behavior I want is as follows.</p>
<p... | 5 | 2009-04-23T11:53:09Z | 782,208 | <p>While I do not know any specific tool to do this, here is the basic approach I would take: <br></p>
<p>Load as xml document <br>
Extract the css classes and styles from document <br>
For each pair of css class and style <br>
Construct xpath query from css class <br>
For each matching node<br... | 1 | 2009-04-23T15:17:44Z | [
"python",
"css",
"parsing",
"xhtml"
] |
CSS parser + XHTML generator, advice needed | 781,382 | <p>Guys, I need to develop a tool which would meet following requirements:</p>
<ol>
<li>Input: XHTML document with CSS rules within <code>head</code> section. </li>
<li>Output: XHTML document with CSS rules computed in tag attributes</li>
</ol>
<p>The best way to illustrate the behavior I want is as follows.</p>
<p... | 5 | 2009-04-23T11:53:09Z | 1,693,936 | <p>There is a <a href="http://pypi.python.org/pypi/premailer" rel="nofollow">premailer python package on Pypi</a></p>
| 1 | 2009-11-07T18:17:01Z | [
"python",
"css",
"parsing",
"xhtml"
] |
Python3 Http Web Server: virtual hosts | 781,466 | <p>I am writing an rather simple http web server in python3. The web server needs to be simple - only basic reading from config files, etc. I am using only standard libraries and for now it works rather ok. </p>
<p>There is only one requirement for this project, which I can't implement on my own - virtual hosts. I nee... | 2 | 2009-04-23T12:20:12Z | 781,474 | <p>Virtual hosts work by obeying the Host: header in the HTTP request.</p>
<p>Just read the headers of the request, and take action based on the value of the Host: header</p>
| 10 | 2009-04-23T12:22:59Z | [
"python",
"http",
"python-3.x",
"virtualhost"
] |
Python3 Http Web Server: virtual hosts | 781,466 | <p>I am writing an rather simple http web server in python3. The web server needs to be simple - only basic reading from config files, etc. I am using only standard libraries and for now it works rather ok. </p>
<p>There is only one requirement for this project, which I can't implement on my own - virtual hosts. I nee... | 2 | 2009-04-23T12:20:12Z | 961,575 | <p>For a simple HTTP web server, you can start with the <a href="http://docs.python.org/3.0/library/wsgiref.html#module-wsgiref">WSGI reference implementation</a>:</p>
<blockquote>
<p>wsgiref is a reference implementation of the WSGI specification that can be used to add WSGI support to a web server or framework. It... | 5 | 2009-06-07T09:36:36Z | [
"python",
"http",
"python-3.x",
"virtualhost"
] |
Communicating with a Python service | 781,594 | <p><strong>Problem:</strong></p>
<p>I have a python script that I have running as a service. It's a subclass of the win32 class win32serviceutil.ServiceFramework. I want a simple straightforward way of sending arbitrary commands to it via the command line. </p>
<p><strong>What I've looked at:</strong></p>
<p>It l... | 0 | 2009-04-23T13:06:03Z | 781,778 | <p>Not really.</p>
<p>You have many, many ways to do "Interprocess Communication" (IPC) in Python.</p>
<ul>
<li><p><a href="http://docs.python.org/library/socket.html" rel="nofollow">Sockets</a></p></li>
<li><p>Named Pipes (see <a href="http://developers.sun.com/solaris/articles/named_pipes.html" rel="nofollow">http:... | 2 | 2009-04-23T13:45:33Z | [
"python",
"winapi",
"command-line",
"service"
] |
How to hide __methods__ in python? | 781,667 | <p>I just wondered, how to hide special </p>
<pre><code>__.*__
</code></pre>
<p>methods in python*? Especially I am using an interactive python interpreter with tab-completion, and I would like to display only the methods my modules expose ... </p>
<p>thanks,</p>
<p>/ myyn /</p>
<p>*(at least from the user, who u... | 5 | 2009-04-23T13:25:29Z | 781,790 | <p>I think you should look for a way to get that particular environment/interpreter to stop displaying the "private" methods when you press TAB. I don't think there is a way to "hide" methods from Python itself, that would be very weird.</p>
| 3 | 2009-04-23T13:49:04Z | [
"python",
"hide",
"magic-methods",
"facade"
] |
How to hide __methods__ in python? | 781,667 | <p>I just wondered, how to hide special </p>
<pre><code>__.*__
</code></pre>
<p>methods in python*? Especially I am using an interactive python interpreter with tab-completion, and I would like to display only the methods my modules expose ... </p>
<p>thanks,</p>
<p>/ myyn /</p>
<p>*(at least from the user, who u... | 5 | 2009-04-23T13:25:29Z | 782,231 | <p>I would take a look into ipython. Maybe your are able to hook ipythons interactive shell without an subprocess into your app and apply the private method filtering from there.</p>
| 1 | 2009-04-23T15:21:24Z | [
"python",
"hide",
"magic-methods",
"facade"
] |
How to hide __methods__ in python? | 781,667 | <p>I just wondered, how to hide special </p>
<pre><code>__.*__
</code></pre>
<p>methods in python*? Especially I am using an interactive python interpreter with tab-completion, and I would like to display only the methods my modules expose ... </p>
<p>thanks,</p>
<p>/ myyn /</p>
<p>*(at least from the user, who u... | 5 | 2009-04-23T13:25:29Z | 782,676 | <p>Well, you could create a subclass of <code>rlcompleter.Completer</code>, override
the methods in question, and install that into <code>readline</code>.</p>
<pre><code>import rlcompleter
import readline
class MyCompleter(rlcompleter.Completer):
def global_matches(self, text):
....
def attr_matches(se... | 3 | 2009-04-23T17:06:45Z | [
"python",
"hide",
"magic-methods",
"facade"
] |
Penalties of a script constantly looping in the background | 781,896 | <p>I know this topic has been <a href="http://stackoverflow.com/questions/680921#681336">discussed</a> in the <a href="http://stackoverflow.com/questions/379231">past</a>, but I am a tiny bit paranoid about resource usage.</p>
<p>I am looking into writing a daemon for queing jobs to archive files into zip files for a ... | 0 | 2009-04-23T14:08:25Z | 781,909 | <p>This has the potential to hammer your CPU, even when there is nothing to process.</p>
<p><strong>Edit:</strong> Actually <a href="http://docs.python.org/library/time.html#time.sleep" rel="nofollow"><code>sleep()</code></a> takes an argument as a number of seconds, not milliseconds so I don't think the CPU is going ... | 0 | 2009-04-23T14:10:24Z | [
"python",
"resources",
"performance",
"queue"
] |
Penalties of a script constantly looping in the background | 781,896 | <p>I know this topic has been <a href="http://stackoverflow.com/questions/680921#681336">discussed</a> in the <a href="http://stackoverflow.com/questions/379231">past</a>, but I am a tiny bit paranoid about resource usage.</p>
<p>I am looking into writing a daemon for queing jobs to archive files into zip files for a ... | 0 | 2009-04-23T14:08:25Z | 781,913 | <p>Instead of sleeping for 15 seconds, it might be better to have a callback which restarts your job when new files arrive.</p>
<ul>
<li>Process available files</li>
<li>Check for new files every 60 seconds or whatever interval you choose</li>
<li>When a new file arrives, process it and any others which may have arriv... | 1 | 2009-04-23T14:11:03Z | [
"python",
"resources",
"performance",
"queue"
] |
Penalties of a script constantly looping in the background | 781,896 | <p>I know this topic has been <a href="http://stackoverflow.com/questions/680921#681336">discussed</a> in the <a href="http://stackoverflow.com/questions/379231">past</a>, but I am a tiny bit paranoid about resource usage.</p>
<p>I am looking into writing a daemon for queing jobs to archive files into zip files for a ... | 0 | 2009-04-23T14:08:25Z | 781,930 | <p>Why not just use a cron job to run a script every minute or so? At least you are not depending on your own loop to be continuously running in the background.</p>
| 1 | 2009-04-23T14:12:58Z | [
"python",
"resources",
"performance",
"queue"
] |
Penalties of a script constantly looping in the background | 781,896 | <p>I know this topic has been <a href="http://stackoverflow.com/questions/680921#681336">discussed</a> in the <a href="http://stackoverflow.com/questions/379231">past</a>, but I am a tiny bit paranoid about resource usage.</p>
<p>I am looking into writing a daemon for queing jobs to archive files into zip files for a ... | 0 | 2009-04-23T14:08:25Z | 781,934 | <p>Besides the cost of hammering your cpu, there is the cost of the <em>morejobs()</em> call. You can mitigate by using a higher value for <em>sleep()</em>, or you can use some sort of mailbox that receives requests and then fires the <em>zipfile()</em> operation.</p>
<p>It is normal for some operations to have a back... | 0 | 2009-04-23T14:13:41Z | [
"python",
"resources",
"performance",
"queue"
] |
Penalties of a script constantly looping in the background | 781,896 | <p>I know this topic has been <a href="http://stackoverflow.com/questions/680921#681336">discussed</a> in the <a href="http://stackoverflow.com/questions/379231">past</a>, but I am a tiny bit paranoid about resource usage.</p>
<p>I am looking into writing a daemon for queing jobs to archive files into zip files for a ... | 0 | 2009-04-23T14:08:25Z | 781,948 | <p>If it takes (and these figures are examples) 20 seconds for a file to arrive and 5 seconds for you to process it, what is the harm in your process waiting for, on average, another 7.5 seconds before it even detects that the file is there?</p>
<p>A sleeping process should have as close to zero impact on the CPU as i... | 1 | 2009-04-23T14:16:01Z | [
"python",
"resources",
"performance",
"queue"
] |
Penalties of a script constantly looping in the background | 781,896 | <p>I know this topic has been <a href="http://stackoverflow.com/questions/680921#681336">discussed</a> in the <a href="http://stackoverflow.com/questions/379231">past</a>, but I am a tiny bit paranoid about resource usage.</p>
<p>I am looking into writing a daemon for queing jobs to archive files into zip files for a ... | 0 | 2009-04-23T14:08:25Z | 781,980 | <p>Sleep involves no overhead. The Linux OS uses a very simple signal to wake a sleeping process.</p>
<p>What you're showing is the "busy-waiting" design pattern.</p>
<p>To eliminate overhead, you want to be woken ONLY when there's work to do.</p>
<p>Ways to do this.</p>
<ol>
<li><p>Wait on read.</p></li>
<li><p>W... | 4 | 2009-04-23T14:22:10Z | [
"python",
"resources",
"performance",
"queue"
] |
Penalties of a script constantly looping in the background | 781,896 | <p>I know this topic has been <a href="http://stackoverflow.com/questions/680921#681336">discussed</a> in the <a href="http://stackoverflow.com/questions/379231">past</a>, but I am a tiny bit paranoid about resource usage.</p>
<p>I am looking into writing a daemon for queing jobs to archive files into zip files for a ... | 0 | 2009-04-23T14:08:25Z | 783,881 | <p>"A thousand reasoned opinions are worth one measurement". </p>
<p>Just try it.</p>
| 0 | 2009-04-23T22:50:54Z | [
"python",
"resources",
"performance",
"queue"
] |
Penalties of a script constantly looping in the background | 781,896 | <p>I know this topic has been <a href="http://stackoverflow.com/questions/680921#681336">discussed</a> in the <a href="http://stackoverflow.com/questions/379231">past</a>, but I am a tiny bit paranoid about resource usage.</p>
<p>I am looking into writing a daemon for queing jobs to archive files into zip files for a ... | 0 | 2009-04-23T14:08:25Z | 784,315 | <p>As an alternative you can lower the priority of your process.
(I'm only familiar with the windows method)</p>
<p>On Windows:</p>
<pre><code>def setpriority(pid=None,priority=1):
""" Set The Priority of a Windows Process. Priority is a value between 0-5 where
2 is normal priority. Default sets the pri... | 1 | 2009-04-24T02:30:45Z | [
"python",
"resources",
"performance",
"queue"
] |
Qt and context menu | 782,255 | <p>i need to create a context menu on right clicking at my window. But i really don't know what should i do. Are there any widgets or i must make it by my hands?
Programming language: Python
Graphical lib: Qt (PyQt).</p>
| 14 | 2009-04-23T15:26:41Z | 782,462 | <p>I can't speak for python, but it's fairly easy in C++.</p>
<p>first after creating the widget you set the policy:</p>
<pre><code>w->setContextMenuPolicy(Qt::CustomContextMenu);
</code></pre>
<p>then you connect the context menu event to a slot:</p>
<pre><code>connect(w, SIGNAL(customContextMenuRequested(const... | 39 | 2009-04-23T16:14:44Z | [
"python",
"qt",
"pyqt",
"menu"
] |
Qt and context menu | 782,255 | <p>i need to create a context menu on right clicking at my window. But i really don't know what should i do. Are there any widgets or i must make it by my hands?
Programming language: Python
Graphical lib: Qt (PyQt).</p>
| 14 | 2009-04-23T15:26:41Z | 958,969 | <p>Another example which shows how to use actions in a toolbar and context menu.</p>
<pre><code>class Foo( QtGui.QWidget ):
def __init__(self):
QtGui.QWidget.__init__(self, None)
mainLayout = QtGui.QVBoxLayout()
self.setLayout(mainLayout)
# Toolbar
toolbar = QtGui.QToolBar... | 14 | 2009-06-06T04:07:47Z | [
"python",
"qt",
"pyqt",
"menu"
] |
Emacs function to message the python function I'm in | 782,357 | <p>I'm editing some Python code with rather long functions and decided it would be useful to quickly get the function name without scrolling up. I put this bit of code together to do it. Is there something built in to emacs in general, or the standard python mode in particular, which I can use instead?</p>
<pre><code>... | 10 | 2009-04-23T15:50:22Z | 782,411 | <p>C-c C-u (py-goto-block-up) might be what you want.</p>
| 0 | 2009-04-23T16:00:53Z | [
"python",
"emacs",
"elisp"
] |
Emacs function to message the python function I'm in | 782,357 | <p>I'm editing some Python code with rather long functions and decided it would be useful to quickly get the function name without scrolling up. I put this bit of code together to do it. Is there something built in to emacs in general, or the standard python mode in particular, which I can use instead?</p>
<pre><code>... | 10 | 2009-04-23T15:50:22Z | 782,413 | <p>You may find decent results with <a href="http://www.gnu.org/software/emacs/manual/html%5Fnode/emacs/Which-Function.html">which-function-mode</a>:</p>
<blockquote>
<p>Which Function mode is a minor mode
that displays the current function
name in the mode line, updating it as
you move around in a buffer.</p>... | 21 | 2009-04-23T16:01:39Z | [
"python",
"emacs",
"elisp"
] |
Emacs function to message the python function I'm in | 782,357 | <p>I'm editing some Python code with rather long functions and decided it would be useful to quickly get the function name without scrolling up. I put this bit of code together to do it. Is there something built in to emacs in general, or the standard python mode in particular, which I can use instead?</p>
<pre><code>... | 10 | 2009-04-23T15:50:22Z | 782,445 | <p>Did you try <code>py-beginning-of-def-or-class</code>?</p>
<pre><code>(defun python-show-function-name()
"Message the name of the function the point is in"
(interactive)
(save-excursion
(py-beginning-of-def-or-class)
(message (format "%s" (thing-at-point 'line)))))
</code></pre>
<p>I find it gives me... | 2 | 2009-04-23T16:09:00Z | [
"python",
"emacs",
"elisp"
] |
Implementing a 'function-calling function' | 782,605 | <p>I would like to write a bit of code that calls a function specified by a given argument. EG:</p>
<pre><code>def caller(func):
return func()
</code></pre>
<p>However what I would also like to do is specify optional arguments to the 'caller' function so that 'caller' calls 'func' with the arguments specified (i... | 0 | 2009-04-23T16:50:16Z | 782,609 | <p>You can do this by using <a href="http://docs.python.org/tutorial/controlflow.html#arbitrary-argument-lists" rel="nofollow">arbitrary argument lists</a> and <a href="http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists" rel="nofollow">unpacking argument lists</a>.</p>
<pre><code>>>> de... | 12 | 2009-04-23T16:51:20Z | [
"function",
"functional-programming",
"python"
] |
Implementing a 'function-calling function' | 782,605 | <p>I would like to write a bit of code that calls a function specified by a given argument. EG:</p>
<pre><code>def caller(func):
return func()
</code></pre>
<p>However what I would also like to do is specify optional arguments to the 'caller' function so that 'caller' calls 'func' with the arguments specified (i... | 0 | 2009-04-23T16:50:16Z | 782,627 | <p>This already exists as the <a href="http://docs.python.org/library/functions.html#apply" rel="nofollow">apply</a> function, though it is considered obsolete due to the new *args and **kwargs syntax.</p>
<pre><code>>>> def foo(a,b,c): print a,b,c
>>> apply(foo, (1,2,3))
1 2 3
>>> apply(foo... | 7 | 2009-04-23T16:56:01Z | [
"function",
"functional-programming",
"python"
] |
wxPython: Using EVT_IDLE | 783,023 | <p>I defined an handler for <code>EVT_IDLE</code> that does a certain background task for me. (That task is to take completed work from a few processes and integrate it into some object, making a visible change in the GUI.)</p>
<p>The problem is that when the user is not moving the mouse or doing anything, <code>EVT_I... | 3 | 2009-04-23T18:45:30Z | 783,386 | <p>Something like this (executes at most every second):</p>
<pre><code>...
def On_Idle(self, event):
if not self.queued_batch:
wx.CallLater(1000, self.Do_Batch)
self.queued_batch = True
def Do_Batch(self):
# <- insert your stuff here
self.queued_batch = False
...
</code></pre>
<p>Oh,... | 2 | 2009-04-23T20:27:04Z | [
"python",
"wxpython"
] |
wxPython: Using EVT_IDLE | 783,023 | <p>I defined an handler for <code>EVT_IDLE</code> that does a certain background task for me. (That task is to take completed work from a few processes and integrate it into some object, making a visible change in the GUI.)</p>
<p>The problem is that when the user is not moving the mouse or doing anything, <code>EVT_I... | 3 | 2009-04-23T18:45:30Z | 783,439 | <p>This sounds like a use case for wxTimerEvent instead of wxIdleEvent. When there is processing to do call wxTimerEvent.Start(). When there isn't any to do, call wxTimerEvent.Stop() and call your methods to do processing from EVT_TIMER.</p>
<p>(note: i use from wxWidghets for C++ and am not familiar with wxPython b... | 0 | 2009-04-23T20:43:20Z | [
"python",
"wxpython"
] |
English and/or Finnish text validation | 783,189 | <p>Is there an easy-to-use python module that'd do english or finnish text validation?</p>
<p>It'd be ok if I could just check the words exist in user-defined dictionary and possibly checking that the grammar is somewhat okay.</p>
<p>I am planning to implement a fancy validation for a directory contents I did while a... | 0 | 2009-04-23T19:27:10Z | 783,207 | <p>I'm not sure what you're trying to do, but if you're looking for something that can say 'this is valid English' or 'this is valid Finnish', then you're looking at a class of problems that is quite likely unsolvable.</p>
<p>If not, then use a dictionary and/or letter frequencies and Bayesian analysis to determine wh... | 2 | 2009-04-23T19:32:06Z | [
"python"
] |
Creating a tree from a list of tuples | 783,217 | <p>I seem to be blind at the moment, so I need to ask here. I want to sort a list of tuples which look like that</p>
<pre><code>(id, parent_id, value)
</code></pre>
<p>So that it is a representation of the tree as a flattend list of list of tree nodes.</p>
<p>For example the input</p>
<pre><code>(1, None, '...')
(3... | 2 | 2009-04-23T19:34:26Z | 783,240 | <p>Python sorts tuples from left to right, so if you arrange your tuples so the first sort key is the first item and so forth, it'll be reasonably efficient.</p>
<p>The mapping from a list of tuples to a tree is not clear from what you're describing. Please draw it out, or explain it more thoroughly. For example, yo... | 2 | 2009-04-23T19:44:51Z | [
"python",
"sorting",
"tree"
] |
Creating a tree from a list of tuples | 783,217 | <p>I seem to be blind at the moment, so I need to ask here. I want to sort a list of tuples which look like that</p>
<pre><code>(id, parent_id, value)
</code></pre>
<p>So that it is a representation of the tree as a flattend list of list of tree nodes.</p>
<p>For example the input</p>
<pre><code>(1, None, '...')
(3... | 2 | 2009-04-23T19:34:26Z | 783,313 | <p>I'm not sure I've quite follows what you are exactly trying to do, but if you have a forest as a list of nodes, can't you just read it and build the tree structure, then write it out as a bread-first traversal of all the trees? Any particular reason to avoid this?</p>
| 1 | 2009-04-23T20:04:04Z | [
"python",
"sorting",
"tree"
] |
Creating a tree from a list of tuples | 783,217 | <p>I seem to be blind at the moment, so I need to ask here. I want to sort a list of tuples which look like that</p>
<pre><code>(id, parent_id, value)
</code></pre>
<p>So that it is a representation of the tree as a flattend list of list of tree nodes.</p>
<p>For example the input</p>
<pre><code>(1, None, '...')
(3... | 2 | 2009-04-23T19:34:26Z | 1,790,387 | <p>Oliver, if I understand correctly, I think you can either
(a) retrieve all tuples from your database into a dictionary or list, and then construct the tree,
OR
(b) use an ORDER BY clause when you retrieve the tuples so that they are in the order in which you will add them to the tree. </p>
<p>If changes to the tre... | 0 | 2009-11-24T14:22:51Z | [
"python",
"sorting",
"tree"
] |
Send data to the browser while waiting (Python) | 783,262 | <p>I have the following code</p>
<pre><code>print "Starting stage 1<br>"
# Something that takes about 5 seconds
time.sleep(5)
print "Stage 1 complete"
</code></pre>
<p>I view the script with my browser as it's part of a web-app, the problem is that it's displaying all of it together. I want it to display firs... | 3 | 2009-04-23T19:47:43Z | 783,268 | <p>Try flush the output after the first print using sys.stdout.<a href="http://docs.python.org/library/stdtypes.html#file.flush" rel="nofollow">flush()</a></p>
| 5 | 2009-04-23T19:49:38Z | [
"python"
] |
Pylons or TurboGears vs. .NET or Java | 783,488 | <p>We're embarking on a project for a client. They plan on having about 50k users by the end of the year. We're pushing to use Pylons w/ Mako and SQLAlchemy, and our contact there is excited about it, but some of his colleagues are wary because it's not .NET or J2ee (they're used to enterprisey stuff).</p>
<p>Their w... | 4 | 2009-04-23T20:57:23Z | 783,515 | <p>It's almost easier to build a quick Proof of Concept service that demonstrates how clean and simple it is.</p>
<p>A simple SQLAlchemy mapping with a quick demo of query processing.</p>
<p>A simple template showing how cool Mako is.</p>
<p>A simple Pylons app to put the two together.</p>
<p>Most important -- use ... | 3 | 2009-04-23T21:03:33Z | [
"java",
"python",
"java-ee",
"pylons",
"wsgi"
] |
Pylons or TurboGears vs. .NET or Java | 783,488 | <p>We're embarking on a project for a client. They plan on having about 50k users by the end of the year. We're pushing to use Pylons w/ Mako and SQLAlchemy, and our contact there is excited about it, but some of his colleagues are wary because it's not .NET or J2ee (they're used to enterprisey stuff).</p>
<p>Their w... | 4 | 2009-04-23T20:57:23Z | 784,406 | <p>If you're looking for a success story for a customer, <a href="http://virgincharter.com/" rel="nofollow">Virgin Charter</a> is using Pylons with SQLAlchemy for their site. This is a high-value transaction system as people are booking very expensive flights through the site.</p>
<p>For a more high-traffic site, Redd... | 5 | 2009-04-24T03:37:22Z | [
"java",
"python",
"java-ee",
"pylons",
"wsgi"
] |
Pylons or TurboGears vs. .NET or Java | 783,488 | <p>We're embarking on a project for a client. They plan on having about 50k users by the end of the year. We're pushing to use Pylons w/ Mako and SQLAlchemy, and our contact there is excited about it, but some of his colleagues are wary because it's not .NET or J2ee (they're used to enterprisey stuff).</p>
<p>Their w... | 4 | 2009-04-23T20:57:23Z | 821,380 | <p>They are crazy if they want to use j2ee imho. Visual Studio/C# is very nice, especially if you are not trying to do anything tricky. However, if you want to customize the C# way of doing things beyond what it was explicitly designed for it can quickly turn into a mess -- you get mired in automatically generated XM... | -1 | 2009-05-04T18:52:04Z | [
"java",
"python",
"java-ee",
"pylons",
"wsgi"
] |
how to run a python script in the background? | 783,531 | <p>I have a script which checking something on my pc every 5 min and I dont want python to show on my tasktray</p>
<p>is there any way to make python run in the background and force him not to show in my task tray ?</p>
<p>thanks</p>
<p>im using windows by the way</p>
| 10 | 2009-04-23T21:07:49Z | 783,541 | <p>cron it on linux; schedule it on windows [control panel > scheduled tasks > Add scheduled task]</p>
| 1 | 2009-04-23T21:10:36Z | [
"python",
"windows",
"backgrounding"
] |
how to run a python script in the background? | 783,531 | <p>I have a script which checking something on my pc every 5 min and I dont want python to show on my tasktray</p>
<p>is there any way to make python run in the background and force him not to show in my task tray ?</p>
<p>thanks</p>
<p>im using windows by the way</p>
| 10 | 2009-04-23T21:07:49Z | 783,544 | <p>Look for Schedule Tasks in the control panel.</p>
| 2 | 2009-04-23T21:11:09Z | [
"python",
"windows",
"backgrounding"
] |
how to run a python script in the background? | 783,531 | <p>I have a script which checking something on my pc every 5 min and I dont want python to show on my tasktray</p>
<p>is there any way to make python run in the background and force him not to show in my task tray ?</p>
<p>thanks</p>
<p>im using windows by the way</p>
| 10 | 2009-04-23T21:07:49Z | 783,555 | <p>If you run a console script using <code>pythonw.exe</code>, it will neither display a window nor appear in the task bar. For example, I use the following command to launch <a href="http://ntlmaps.sourceforge.net/">ntlmaps</a> on startup:</p>
<pre><code>C:\BenBlank\Python2.6\pythonw.exe scripts/ntlmaps
</code></pre... | 37 | 2009-04-23T21:15:11Z | [
"python",
"windows",
"backgrounding"
] |
how to run a python script in the background? | 783,531 | <p>I have a script which checking something on my pc every 5 min and I dont want python to show on my tasktray</p>
<p>is there any way to make python run in the background and force him not to show in my task tray ?</p>
<p>thanks</p>
<p>im using windows by the way</p>
| 10 | 2009-04-23T21:07:49Z | 783,559 | <p>Just another option you have:</p>
<p>You can create a shortcut to your Python script, then <code>right-click the shortcut --> Properties --> Shortcut tab</code></p>
<p>There is a drop-down box under the Run option which lets you <strong>run the command minimized.</strong></p>
| 2 | 2009-04-23T21:17:50Z | [
"python",
"windows",
"backgrounding"
] |
how to run a python script in the background? | 783,531 | <p>I have a script which checking something on my pc every 5 min and I dont want python to show on my tasktray</p>
<p>is there any way to make python run in the background and force him not to show in my task tray ?</p>
<p>thanks</p>
<p>im using windows by the way</p>
| 10 | 2009-04-23T21:07:49Z | 810,596 | <p>You could run it as a service. See <a href="http://code.activestate.com/recipes/551780/" rel="nofollow">here</a></p>
| 1 | 2009-05-01T08:07:51Z | [
"python",
"windows",
"backgrounding"
] |
Python equivalent of PHP's compact() and extract() | 783,781 | <p><a href="http://www.php.net/compact">compact</a>() and <a href="http://www.php.net/extract">extract</a>() are functions in PHP I find tremendously handy. compact() takes a list of names in the symbol table and creates a hashtable with just their values. extract does the opposite. e.g.,</p>
<pre><code>$foo = 'wha... | 7 | 2009-04-23T22:21:29Z | 783,812 | <p>I guess the equivalent of <code>extract($x)</code> is <code>globals().update(x)</code>, as for <code>compact()</code> it's a subset of <code>vars()</code></p>
<pre><code>>>> foo, bar, baz = 1, 2, 3
# extract
>>> globals().update({"foo": 4, "qux": 5})
>>> foo
4
>>> qux
5
# compact... | 2 | 2009-04-23T22:32:56Z | [
"php",
"python",
"dictionary"
] |
Python equivalent of PHP's compact() and extract() | 783,781 | <p><a href="http://www.php.net/compact">compact</a>() and <a href="http://www.php.net/extract">extract</a>() are functions in PHP I find tremendously handy. compact() takes a list of names in the symbol table and creates a hashtable with just their values. extract does the opposite. e.g.,</p>
<pre><code>$foo = 'wha... | 7 | 2009-04-23T22:21:29Z | 783,839 | <p>I'm afraid there are no equivalents in Python. To some extent, you can simulate their effect using (and passing) <code>locals</code>:</p>
<pre><code>>>> def compact(locals, *keys):
... return dict((k, locals[k]) for k in keys)
...
>>> a = 10
>>> b = 2
>>> compact(locals(), 'a... | 8 | 2009-04-23T22:40:07Z | [
"php",
"python",
"dictionary"
] |
Python equivalent of PHP's compact() and extract() | 783,781 | <p><a href="http://www.php.net/compact">compact</a>() and <a href="http://www.php.net/extract">extract</a>() are functions in PHP I find tremendously handy. compact() takes a list of names in the symbol table and creates a hashtable with just their values. extract does the opposite. e.g.,</p>
<pre><code>$foo = 'wha... | 7 | 2009-04-23T22:21:29Z | 783,867 | <p>It's not very Pythonic, but if you really must:</p>
<pre><code>import inspect
def compact(*names):
caller = inspect.stack()[1][0] # caller of compact()
vars = {}
for n in names:
if n in caller.f_locals:
vars[n] = caller.f_locals[n]
elif n in caller.f_globals:
var... | 9 | 2009-04-23T22:47:46Z | [
"php",
"python",
"dictionary"
] |
Python equivalent of PHP's compact() and extract() | 783,781 | <p><a href="http://www.php.net/compact">compact</a>() and <a href="http://www.php.net/extract">extract</a>() are functions in PHP I find tremendously handy. compact() takes a list of names in the symbol table and creates a hashtable with just their values. extract does the opposite. e.g.,</p>
<pre><code>$foo = 'wha... | 7 | 2009-04-23T22:21:29Z | 784,681 | <p>Is it worth pointing out that <code>extract()</code> (and to a lesser extent, <code>compact()</code>) is one of the most "evil" features of PHP (along with <code>register_globals</code> and <code>eval</code>), and should be avoided?</p>
<p><a href="http://php.net/manual/en/function.extract.php" rel="nofollow"><code... | 6 | 2009-04-24T05:57:58Z | [
"php",
"python",
"dictionary"
] |
Python equivalent of PHP's compact() and extract() | 783,781 | <p><a href="http://www.php.net/compact">compact</a>() and <a href="http://www.php.net/extract">extract</a>() are functions in PHP I find tremendously handy. compact() takes a list of names in the symbol table and creates a hashtable with just their values. extract does the opposite. e.g.,</p>
<pre><code>$foo = 'wha... | 7 | 2009-04-23T22:21:29Z | 864,868 | <p>PHP's compact function in Python (works with 2.6; not guaranteed to work with earlier versions of Python):</p>
<pre><code>import inspect
def compact(*args):
return dict([(i, inspect.currentframe().f_back.f_locals.get(i, None))
for i in args])
</code></pre>
<p>I've written more extensively ab... | 3 | 2009-05-14T18:13:24Z | [
"php",
"python",
"dictionary"
] |
Python equivalent of PHP's compact() and extract() | 783,781 | <p><a href="http://www.php.net/compact">compact</a>() and <a href="http://www.php.net/extract">extract</a>() are functions in PHP I find tremendously handy. compact() takes a list of names in the symbol table and creates a hashtable with just their values. extract does the opposite. e.g.,</p>
<pre><code>$foo = 'wha... | 7 | 2009-04-23T22:21:29Z | 39,669,396 | <p>You <em>can</em> do this (though I would suggest only sparingly...) with the <code>locals()</code> function, which returns an updatable <code>dict</code>. Example:</p>
<pre><code>$ python
Python 2.7.12 (default, Jul 1 2016, 15:12:24)
>>> locals().update({'derek':'anderson'})
>>> derek
'anderson... | 1 | 2016-09-23T20:54:37Z | [
"php",
"python",
"dictionary"
] |
seek(), then read(), then write() in python | 783,792 | <p>When running the following python code:</p>
<pre><code>>>> f = open(r"myfile.txt", "a+")
>>> f.seek(-1,2)
>>> f.read()
'a'
>>> f.write(... | 6 | 2009-04-23T22:25:29Z | 783,805 | <p>the a+ mode is for appending, if you want to read & write, you are looking for r+.</p>
<p>try this:</p>
<pre><code>>>> f = open("myfile.txt", "r+")
>>> f.write('\n')
</code></pre>
<p><strong>Edit:</strong></p>
<p>you should have specified your platform initially... there are known problems ... | 1 | 2009-04-23T22:30:09Z | [
"python",
"file-io"
] |
seek(), then read(), then write() in python | 783,792 | <p>When running the following python code:</p>
<pre><code>>>> f = open(r"myfile.txt", "a+")
>>> f.seek(-1,2)
>>> f.read()
'a'
>>> f.write(... | 6 | 2009-04-23T22:25:29Z | 783,843 | <p>This appears to be a Windows-specific problem - see <a href="http://bugs.python.org/issue1521491" rel="nofollow">http://bugs.python.org/issue1521491</a> for a similar issue.</p>
<p>Even better, a workaround given and explained at <a href="http://mail.python.org/pipermail/python-bugs-list/2005-August/029886.html" re... | 3 | 2009-04-23T22:41:18Z | [
"python",
"file-io"
] |
seek(), then read(), then write() in python | 783,792 | <p>When running the following python code:</p>
<pre><code>>>> f = open(r"myfile.txt", "a+")
>>> f.seek(-1,2)
>>> f.read()
'a'
>>> f.write(... | 6 | 2009-04-23T22:25:29Z | 783,852 | <p>Works for me:</p>
<pre><code>$ echo hello > myfile.txt
$ python
Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open('myfile.txt', 'r+')
>>> f.seek(-1, 2)
>>> f.tell()
5L
>>>... | 0 | 2009-04-23T22:43:23Z | [
"python",
"file-io"
] |
Truncating floats in Python | 783,897 | <p>I want to remove digits from a float to have a fixed number of digits after the dot, like:</p>
<pre><code>1.923328437452 -> 1.923
</code></pre>
<p>I need to output as a string to another function, not print.</p>
<p>Also I want to ignore the lost digits, not round them.</p>
| 46 | 2009-04-23T22:56:44Z | 783,900 | <pre><code>round(1.923328437452, 3)
</code></pre>
<p>See <a href="http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex">Python's documentation on the standard types</a>. You'll need to scroll down a bit to get to the round function. Essentially the second number says how many decimal place... | 94 | 2009-04-23T22:59:15Z | [
"python",
"floating-point"
] |
Truncating floats in Python | 783,897 | <p>I want to remove digits from a float to have a fixed number of digits after the dot, like:</p>
<pre><code>1.923328437452 -> 1.923
</code></pre>
<p>I need to output as a string to another function, not print.</p>
<p>Also I want to ignore the lost digits, not round them.</p>
| 46 | 2009-04-23T22:56:44Z | 783,905 | <p>If you mean when printing, then the following should work:</p>
<pre><code>print '%.3f' % number
</code></pre>
| -3 | 2009-04-23T23:01:35Z | [
"python",
"floating-point"
] |
Truncating floats in Python | 783,897 | <p>I want to remove digits from a float to have a fixed number of digits after the dot, like:</p>
<pre><code>1.923328437452 -> 1.923
</code></pre>
<p>I need to output as a string to another function, not print.</p>
<p>Also I want to ignore the lost digits, not round them.</p>
| 46 | 2009-04-23T22:56:44Z | 783,914 | <p>The result of <code>round</code> is a float, so watch out:</p>
<pre><code>>>> round(1.923328437452, 3)
1.923
>>> round(1.23456, 3)
1.2350000000000001
</code></pre>
<p>You will be better off when using a formatted string:</p>
<pre><code>>>> "%.3f" % 1.923328437452
'1.923'
>>> "%... | 20 | 2009-04-23T23:04:46Z | [
"python",
"floating-point"
] |
Truncating floats in Python | 783,897 | <p>I want to remove digits from a float to have a fixed number of digits after the dot, like:</p>
<pre><code>1.923328437452 -> 1.923
</code></pre>
<p>I need to output as a string to another function, not print.</p>
<p>Also I want to ignore the lost digits, not round them.</p>
| 46 | 2009-04-23T22:56:44Z | 783,927 | <p>First, the function, for those who just want some copy-and-paste code:</p>
<pre><code>def truncate(f, n):
'''Truncates/pads a float f to n decimal places without rounding'''
s = '{}'.format(f)
if 'e' in s or 'E' in s:
return '{0:.{1}f}'.format(f, n)
i, p, d = s.partition('.')
return '.'.... | 53 | 2009-04-23T23:10:44Z | [
"python",
"floating-point"
] |
Truncating floats in Python | 783,897 | <p>I want to remove digits from a float to have a fixed number of digits after the dot, like:</p>
<pre><code>1.923328437452 -> 1.923
</code></pre>
<p>I need to output as a string to another function, not print.</p>
<p>Also I want to ignore the lost digits, not round them.</p>
| 46 | 2009-04-23T22:56:44Z | 784,665 | <pre><code>def trunc(num, digits):
sp = str(num).split('.')
return '.'.join([sp[0], sp[:digits]])
</code></pre>
<p>This should work. It should give you the truncation you are looking for.</p>
| 7 | 2009-04-24T05:46:03Z | [
"python",
"floating-point"
] |
Truncating floats in Python | 783,897 | <p>I want to remove digits from a float to have a fixed number of digits after the dot, like:</p>
<pre><code>1.923328437452 -> 1.923
</code></pre>
<p>I need to output as a string to another function, not print.</p>
<p>Also I want to ignore the lost digits, not round them.</p>
| 46 | 2009-04-23T22:56:44Z | 3,305,306 | <pre><code>def trunc(f,n):
return ('%.16f' % f)[:(n-16)]
</code></pre>
| 1 | 2010-07-22T02:12:26Z | [
"python",
"floating-point"
] |
Truncating floats in Python | 783,897 | <p>I want to remove digits from a float to have a fixed number of digits after the dot, like:</p>
<pre><code>1.923328437452 -> 1.923
</code></pre>
<p>I need to output as a string to another function, not print.</p>
<p>Also I want to ignore the lost digits, not round them.</p>
| 46 | 2009-04-23T22:56:44Z | 3,306,087 | <p>Just wanted to mention that the old "make round() with floor()" trick of</p>
<pre><code>round(f) = floor(f+0.5)
</code></pre>
<p>can be turned around to make floor() from round()</p>
<pre><code>floor(f) = round(f-0.5)
</code></pre>
<p>Although both these rules break around negative numbers, so using it is less t... | 1 | 2010-07-22T05:46:38Z | [
"python",
"floating-point"
] |
Truncating floats in Python | 783,897 | <p>I want to remove digits from a float to have a fixed number of digits after the dot, like:</p>
<pre><code>1.923328437452 -> 1.923
</code></pre>
<p>I need to output as a string to another function, not print.</p>
<p>Also I want to ignore the lost digits, not round them.</p>
| 46 | 2009-04-23T22:56:44Z | 4,176,526 | <pre><code>n = 1.923328437452
str(n)[:4]
</code></pre>
| 11 | 2010-11-14T06:58:32Z | [
"python",
"floating-point"
] |
Truncating floats in Python | 783,897 | <p>I want to remove digits from a float to have a fixed number of digits after the dot, like:</p>
<pre><code>1.923328437452 -> 1.923
</code></pre>
<p>I need to output as a string to another function, not print.</p>
<p>Also I want to ignore the lost digits, not round them.</p>
| 46 | 2009-04-23T22:56:44Z | 7,843,609 | <p>int(16.5);
this will give an integer value of 16, i.e. trunc, won't be able to specify decimals, but guess you can do that by </p>
<pre><code>import math;
def trunc(invalue, digits):
return int(invalue*math.pow(10,digits))/math.pow(10,digits);
</code></pre>
| 1 | 2011-10-20T23:52:03Z | [
"python",
"floating-point"
] |
Truncating floats in Python | 783,897 | <p>I want to remove digits from a float to have a fixed number of digits after the dot, like:</p>
<pre><code>1.923328437452 -> 1.923
</code></pre>
<p>I need to output as a string to another function, not print.</p>
<p>Also I want to ignore the lost digits, not round them.</p>
| 46 | 2009-04-23T22:56:44Z | 11,869,006 | <p>Am also a python newbie and after making use of some bits and pieces here, I offer my two cents</p>
<pre><code>print str(int(time.time()))+str(datetime.now().microsecond)[:3]
</code></pre>
<p>str(int(time.time())) will take the time epoch as int and convert it to string and join with...
str(datetime.now().microsec... | 0 | 2012-08-08T16:30:19Z | [
"python",
"floating-point"
] |
Truncating floats in Python | 783,897 | <p>I want to remove digits from a float to have a fixed number of digits after the dot, like:</p>
<pre><code>1.923328437452 -> 1.923
</code></pre>
<p>I need to output as a string to another function, not print.</p>
<p>Also I want to ignore the lost digits, not round them.</p>
| 46 | 2009-04-23T22:56:44Z | 23,917,385 | <p>The truely pythonic way of doing it is</p>
<pre><code>from decimal import *
with localcontext() as ctx:
ctx.rounding = ROUND_DOWN
print Decimal('1.923328437452').quantize(Decimal('0.001'))
</code></pre>
| 6 | 2014-05-28T16:43:49Z | [
"python",
"floating-point"
] |
Truncating floats in Python | 783,897 | <p>I want to remove digits from a float to have a fixed number of digits after the dot, like:</p>
<pre><code>1.923328437452 -> 1.923
</code></pre>
<p>I need to output as a string to another function, not print.</p>
<p>Also I want to ignore the lost digits, not round them.</p>
| 46 | 2009-04-23T22:56:44Z | 25,702,460 | <p>I did something like this:</p>
<pre><code>from math import trunc
def truncate(number, decimals=0):
if decimals < 0:
raise ValueError('truncate received an invalid value of decimals ({})'.format(decimals))
elif decimals == 0:
return trunc(number)
else:
factor = float(10**deci... | 2 | 2014-09-06T16:42:11Z | [
"python",
"floating-point"
] |
Truncating floats in Python | 783,897 | <p>I want to remove digits from a float to have a fixed number of digits after the dot, like:</p>
<pre><code>1.923328437452 -> 1.923
</code></pre>
<p>I need to output as a string to another function, not print.</p>
<p>Also I want to ignore the lost digits, not round them.</p>
| 46 | 2009-04-23T22:56:44Z | 27,189,591 | <p>Here is an easy way:</p>
<pre><code>def truncate(num, res=3):
return (floor(num*pow(10, res)+0.5))/pow(10, res)
</code></pre>
<p>for num = 1.923328437452, this outputs 1.923</p>
| 0 | 2014-11-28T13:19:53Z | [
"python",
"floating-point"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.