title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
Python with Wiimote using pywiiuse module | 481,943 | <p>After seeing the abilities and hackibility of wiimotes I really want to use it in my 'Intro to programming' final. Everyone must make a python program and present it to the class.</p>
<p>I want to make a game with pygame incorporating a wiimote. I found <a href="http://sourceforge.net/project/showfiles.php?group_... | 3 | 2009-01-27T00:33:04Z | 481,974 | <p><a href="http://code.google.com/p/pywiimote/" rel="nofollow">pywiimote</a> on Google Code might be helpful, if the library you found is failing out on you... give it a try if you have the time.</p>
<p>It seems like a pretty new offering, though, and may not be any better.</p>
<p>Good luck!</p>
| 0 | 2009-01-27T00:48:39Z | [
"python",
"wii"
] |
Python with Wiimote using pywiiuse module | 481,943 | <p>After seeing the abilities and hackibility of wiimotes I really want to use it in my 'Intro to programming' final. Everyone must make a python program and present it to the class.</p>
<p>I want to make a game with pygame incorporating a wiimote. I found <a href="http://sourceforge.net/project/showfiles.php?group_... | 3 | 2009-01-27T00:33:04Z | 484,544 | <p>I'll risk missing the point by suggesting you take a look at WiimoteWhiteboard Java version by Uwe Schmidt</p>
<p><a href="http://www.uweschmidt.org/wiimote-whiteboard" rel="nofollow">http://www.uweschmidt.org/wiimote-whiteboard</a></p>
<p>It uses the WiiRemoteJ library for Java.</p>
<p>I have tried unsuccessfull... | 0 | 2009-01-27T18:12:56Z | [
"python",
"wii"
] |
Python with Wiimote using pywiiuse module | 481,943 | <p>After seeing the abilities and hackibility of wiimotes I really want to use it in my 'Intro to programming' final. Everyone must make a python program and present it to the class.</p>
<p>I want to make a game with pygame incorporating a wiimote. I found <a href="http://sourceforge.net/project/showfiles.php?group_... | 3 | 2009-01-27T00:33:04Z | 678,974 | <p>Been searching for a set of Python wrappers to the Wiimote for almost two days now, here's my summary of the state of the art:</p>
<p>pywiimote (from Google): roughly half-finished, didn't compile when I downloaded the latest version (r52), has some nice ideas, but will require significant investment to get working... | 1 | 2009-03-24T19:49:05Z | [
"python",
"wii"
] |
Python with Wiimote using pywiiuse module | 481,943 | <p>After seeing the abilities and hackibility of wiimotes I really want to use it in my 'Intro to programming' final. Everyone must make a python program and present it to the class.</p>
<p>I want to make a game with pygame incorporating a wiimote. I found <a href="http://sourceforge.net/project/showfiles.php?group_... | 3 | 2009-01-27T00:33:04Z | 1,034,388 | <p>Change your python version to 2.5.2 I believe it will work now</p>
| 0 | 2009-06-23T18:45:22Z | [
"python",
"wii"
] |
Python with Wiimote using pywiiuse module | 481,943 | <p>After seeing the abilities and hackibility of wiimotes I really want to use it in my 'Intro to programming' final. Everyone must make a python program and present it to the class.</p>
<p>I want to make a game with pygame incorporating a wiimote. I found <a href="http://sourceforge.net/project/showfiles.php?group_... | 3 | 2009-01-27T00:33:04Z | 1,844,647 | <p>I know your class is over by now, but for anyone else looking, cwiid is really nice. Installed in Ubuntu like so:</p>
<pre><code>apt-get install libcwiimote-dev python-cwiid
</code></pre>
<p>Or get the latest from <a href="http://github.com/abstrakraft/cwiid" rel="nofollow">github</a>.</p>
<p>Reading wiimote sens... | 1 | 2009-12-04T03:25:10Z | [
"python",
"wii"
] |
Python with Wiimote using pywiiuse module | 481,943 | <p>After seeing the abilities and hackibility of wiimotes I really want to use it in my 'Intro to programming' final. Everyone must make a python program and present it to the class.</p>
<p>I want to make a game with pygame incorporating a wiimote. I found <a href="http://sourceforge.net/project/showfiles.php?group_... | 3 | 2009-01-27T00:33:04Z | 2,936,026 | <p>For those still looking, I found and documented a simple easy way of pairing with the Wii Remote with python using the lightblue library. I tested it on OS X, but it should work cross platform (ie. on Linux)</p>
<p>Here's my writeup: <a href="http://www.borismus.com/prototyping-wii-remote-python/" rel="nofollow">ht... | 1 | 2010-05-29T17:47:14Z | [
"python",
"wii"
] |
Python with Wiimote using pywiiuse module | 481,943 | <p>After seeing the abilities and hackibility of wiimotes I really want to use it in my 'Intro to programming' final. Everyone must make a python program and present it to the class.</p>
<p>I want to make a game with pygame incorporating a wiimote. I found <a href="http://sourceforge.net/project/showfiles.php?group_... | 3 | 2009-01-27T00:33:04Z | 4,002,309 | <p>I updated the pywiiuse wrapper. It didn't seem to be made for the latest version of wiiuse (0.12 at the time of this answer), since much of it just wouldn't work in the current iteration.</p>
<p>I've got the package and some example scripts posted here:
<a href="http://code.google.com/p/pywiiuse/downloads/list" rel... | 3 | 2010-10-23T03:23:01Z | [
"python",
"wii"
] |
Python with Wiimote using pywiiuse module | 481,943 | <p>After seeing the abilities and hackibility of wiimotes I really want to use it in my 'Intro to programming' final. Everyone must make a python program and present it to the class.</p>
<p>I want to make a game with pygame incorporating a wiimote. I found <a href="http://sourceforge.net/project/showfiles.php?group_... | 3 | 2009-01-27T00:33:04Z | 4,290,492 | <p>I've been working with <a href="http://wiimotelib.codeplex.com/" rel="nofollow">wiimotelib</a> for .NET and it is pretty stable. And contains also wii remote extensions like nunchcuk and other.</p>
| 1 | 2010-11-27T06:44:36Z | [
"python",
"wii"
] |
What does the LDAP response tuple (97, []) mean? | 481,995 | <p>I am using python-ldap to try to authenticate against an existing Active Directory, and when I use the following code:</p>
<pre><code>import ldap
l = ldap.initialize('LDAP://example.com')
m = l.simple_bind_s(username@example.com,password)
</code></pre>
<p>I get the following back:</p>
<pre><code>print m
(97, [])
... | 8 | 2009-01-27T00:57:34Z | 482,002 | <p>here is a forum thread that explains the error and provides work around.
<a href="http://www.velocityreviews.com/forums/t612838-pythonldap-operations-error.html" rel="nofollow">http://www.velocityreviews.com/forums/t612838-pythonldap-operations-error.html</a></p>
| 0 | 2009-01-27T01:03:38Z | [
"python",
"active-directory",
"ldap"
] |
What does the LDAP response tuple (97, []) mean? | 481,995 | <p>I am using python-ldap to try to authenticate against an existing Active Directory, and when I use the following code:</p>
<pre><code>import ldap
l = ldap.initialize('LDAP://example.com')
m = l.simple_bind_s(username@example.com,password)
</code></pre>
<p>I get the following back:</p>
<pre><code>print m
(97, [])
... | 8 | 2009-01-27T00:57:34Z | 482,004 | <p>The first item is a status code (97=success) followed by a list of messages from the server.
See <a href="http://www.packtpub.com/article/installing-and-configuring-the-python-ldap-library-and-binding-to-an-ldap-directory" rel="nofollow">here</a> in the section <strong>Binding</strong>. </p>
| 3 | 2009-01-27T01:04:38Z | [
"python",
"active-directory",
"ldap"
] |
What does the LDAP response tuple (97, []) mean? | 481,995 | <p>I am using python-ldap to try to authenticate against an existing Active Directory, and when I use the following code:</p>
<pre><code>import ldap
l = ldap.initialize('LDAP://example.com')
m = l.simple_bind_s(username@example.com,password)
</code></pre>
<p>I get the following back:</p>
<pre><code>print m
(97, [])
... | 8 | 2009-01-27T00:57:34Z | 482,005 | <p>According to the <a href="http://support.microsoft.com/kb/218185">documentation</a>, this is:</p>
<pre><code>LDAP_REFERRAL_LIMIT_EXCEEDED 0x61 The referral limit was exceeded.
</code></pre>
<p>Probably</p>
<pre><code>ldap.set_option(ldap.OPT_REFERRALS, 0)
</code></pre>
<p>could help.</p>
| 5 | 2009-01-27T01:07:38Z | [
"python",
"active-directory",
"ldap"
] |
How would you do the equivalent of preprocessor directives in Python? | 482,014 | <p>Is there a way to do the following preprocessor directives in Python?</p>
<pre><code>#if DEBUG
< do some code >
#else
< do some other code >
#endif
</code></pre>
| 36 | 2009-01-27T01:10:43Z | 482,022 | <p>I suspect you're gonna hate this answer. The way you do that in Python is</p>
<pre><code># code here
if DEBUG:
#debugging code goes here
else:
# other code here.
</code></pre>
<p>Since python is an interpreter, there's no preprocessing step to be applied, and no particular advantage to having a special synt... | 21 | 2009-01-27T01:14:24Z | [
"python",
"preprocessor",
"equivalent",
"directive"
] |
How would you do the equivalent of preprocessor directives in Python? | 482,014 | <p>Is there a way to do the following preprocessor directives in Python?</p>
<pre><code>#if DEBUG
< do some code >
#else
< do some other code >
#endif
</code></pre>
| 36 | 2009-01-27T01:10:43Z | 482,023 | <p>You can just use the normal language constructs:</p>
<pre><code>DEBUG = True
if DEBUG:
# Define a function, a class or do some crazy stuff
def f():
return 23
else:
def f():
return 42
</code></pre>
| 4 | 2009-01-27T01:14:28Z | [
"python",
"preprocessor",
"equivalent",
"directive"
] |
How would you do the equivalent of preprocessor directives in Python? | 482,014 | <p>Is there a way to do the following preprocessor directives in Python?</p>
<pre><code>#if DEBUG
< do some code >
#else
< do some other code >
#endif
</code></pre>
| 36 | 2009-01-27T01:10:43Z | 482,027 | <p>You can use the preprocessor in Python. Just run your scripts through the cpp (C-Preprocessor) in your bin directory. However I've done this with Lua and the benefits of easy interpretation have outweighed the more complex compilation IMHO.</p>
| 9 | 2009-01-27T01:16:14Z | [
"python",
"preprocessor",
"equivalent",
"directive"
] |
How would you do the equivalent of preprocessor directives in Python? | 482,014 | <p>Is there a way to do the following preprocessor directives in Python?</p>
<pre><code>#if DEBUG
< do some code >
#else
< do some other code >
#endif
</code></pre>
| 36 | 2009-01-27T01:10:43Z | 482,244 | <p>There's <code>__debug__</code>, which is a special value that the compiler does preprocess. </p>
<pre><code>if __debug__:
print "If this prints, you're not running python -O."
else:
print "If this prints, you are running python -O!"
</code></pre>
<p><code>__debug__</code> will be replaced with a constant 0 or ... | 79 | 2009-01-27T03:25:06Z | [
"python",
"preprocessor",
"equivalent",
"directive"
] |
How would you do the equivalent of preprocessor directives in Python? | 482,014 | <p>Is there a way to do the following preprocessor directives in Python?</p>
<pre><code>#if DEBUG
< do some code >
#else
< do some other code >
#endif
</code></pre>
| 36 | 2009-01-27T01:10:43Z | 2,987,538 | <p>I wrote a python preprocessor called pypreprocessor that does exactly what you're describing.</p>
<p><a href="http://code.google.com/p/pypreprocessor/">The source and documentation is available on Google Code</a>.</p>
<p><a href="http://pypi.python.org/pypi/pypreprocessor/">The package can also be downloaded/insta... | 19 | 2010-06-07T06:46:27Z | [
"python",
"preprocessor",
"equivalent",
"directive"
] |
How would you do the equivalent of preprocessor directives in Python? | 482,014 | <p>Is there a way to do the following preprocessor directives in Python?</p>
<pre><code>#if DEBUG
< do some code >
#else
< do some other code >
#endif
</code></pre>
| 36 | 2009-01-27T01:10:43Z | 31,261,596 | <p>An alternative method is to use a bash script to comment out portions of code which are only relevant to debugging. Below is an example script which comments out lines that have a '#DEBUG' statement in it. It can also remove these comment markers again.</p>
<pre><code>if [ "$1" == "off" ]; then
sed -e '/^#/! {/#D... | 0 | 2015-07-07T06:47:17Z | [
"python",
"preprocessor",
"equivalent",
"directive"
] |
Replace Nested For Loops... or not | 482,146 | <p>I have a script that loops through a series of four (or less) characters strings. For example:</p>
<pre><code>aaaa
aaab
aaac
aaad
</code></pre>
<p>If have been able to implement it with nested for loops like so:</p>
<pre><code>chars = string.digits + string.uppercase + string.lowercase
for a in chars:
print... | 5 | 2009-01-27T02:27:28Z | 482,168 | <p>There are many algorithms for generating every permutation of a set. What you want here is a related problem, but not directly analagous. <a href="http://en.wikipedia.org/wiki/Permutation#Algorithms_to_generate_permutations" rel="nofollow">Suggested Reading</a></p>
| 1 | 2009-01-27T02:34:44Z | [
"python",
"loops",
"for-loop",
"nested-loops"
] |
Replace Nested For Loops... or not | 482,146 | <p>I have a script that loops through a series of four (or less) characters strings. For example:</p>
<pre><code>aaaa
aaab
aaac
aaad
</code></pre>
<p>If have been able to implement it with nested for loops like so:</p>
<pre><code>chars = string.digits + string.uppercase + string.lowercase
for a in chars:
print... | 5 | 2009-01-27T02:27:28Z | 482,170 | <p>I don't think it's a bad thing, provided you understand (and document :-) it. I don't doubt there may be a more pythonic way or clever solution (with lambdas or whatnot) but I've always favored readability over cleverness.</p>
<p>Since you have to generate all possibilities of 1-, 2-, 3- and 4-character "words", th... | 3 | 2009-01-27T02:35:03Z | [
"python",
"loops",
"for-loop",
"nested-loops"
] |
Replace Nested For Loops... or not | 482,146 | <p>I have a script that loops through a series of four (or less) characters strings. For example:</p>
<pre><code>aaaa
aaab
aaac
aaad
</code></pre>
<p>If have been able to implement it with nested for loops like so:</p>
<pre><code>chars = string.digits + string.uppercase + string.lowercase
for a in chars:
print... | 5 | 2009-01-27T02:27:28Z | 482,173 | <p>Write for the programmer first - the computer second.<br />
If it's clear and obvious to understand then its correct.</p>
<p>If speed matters AND the compiler doesn't optimise it anyway AND if you measure it AND it is the problem - then think of a faster cleverer way!</p>
| 4 | 2009-01-27T02:37:32Z | [
"python",
"loops",
"for-loop",
"nested-loops"
] |
Replace Nested For Loops... or not | 482,146 | <p>I have a script that loops through a series of four (or less) characters strings. For example:</p>
<pre><code>aaaa
aaab
aaac
aaad
</code></pre>
<p>If have been able to implement it with nested for loops like so:</p>
<pre><code>chars = string.digits + string.uppercase + string.lowercase
for a in chars:
print... | 5 | 2009-01-27T02:27:28Z | 482,192 | <pre><code>import string
import itertools
chars = string.digits + string.letters
MAX_CHARS = 4
for nletters in range(MAX_CHARS):
for word in itertools.product(chars, repeat=nletters + 1):
print (''.join(word))
</code></pre>
<p>That'll print all <strong><code>15018570</code></strong> words you're looking f... | 14 | 2009-01-27T02:46:03Z | [
"python",
"loops",
"for-loop",
"nested-loops"
] |
Replace Nested For Loops... or not | 482,146 | <p>I have a script that loops through a series of four (or less) characters strings. For example:</p>
<pre><code>aaaa
aaab
aaac
aaad
</code></pre>
<p>If have been able to implement it with nested for loops like so:</p>
<pre><code>chars = string.digits + string.uppercase + string.lowercase
for a in chars:
print... | 5 | 2009-01-27T02:27:28Z | 482,217 | <p>I'm going to submit my answer as the most readable and least scalable :)</p>
<pre><code>import string
chars = [''] + list(string.lowercase)
strings = (a+b+c+d for a in chars
for b in chars
for c in chars
for d in chars)
for string in strings:
print stri... | 6 | 2009-01-27T03:07:09Z | [
"python",
"loops",
"for-loop",
"nested-loops"
] |
Replace Nested For Loops... or not | 482,146 | <p>I have a script that loops through a series of four (or less) characters strings. For example:</p>
<pre><code>aaaa
aaab
aaac
aaad
</code></pre>
<p>If have been able to implement it with nested for loops like so:</p>
<pre><code>chars = string.digits + string.uppercase + string.lowercase
for a in chars:
print... | 5 | 2009-01-27T02:27:28Z | 482,990 | <p><a href="http://stackoverflow.com/questions/482146/replace-nested-for-loops-or-not#482192">@nosklo's</a> and <a href="http://stackoverflow.com/questions/482146/replace-nested-for-loops-or-not#482217">@Triptych's</a> solutions produce different results:</p>
<pre><code>>>> list(map(''.join, itertools.chain.f... | 2 | 2009-01-27T11:01:47Z | [
"python",
"loops",
"for-loop",
"nested-loops"
] |
Replace Nested For Loops... or not | 482,146 | <p>I have a script that loops through a series of four (or less) characters strings. For example:</p>
<pre><code>aaaa
aaab
aaac
aaad
</code></pre>
<p>If have been able to implement it with nested for loops like so:</p>
<pre><code>chars = string.digits + string.uppercase + string.lowercase
for a in chars:
print... | 5 | 2009-01-27T02:27:28Z | 483,186 | <p>It doesn't exactly answer the question, but this would return the <code>n</code>th combination for the given maximum length and characters in the alphabet to use:</p>
<pre><code>#!/usr/bin/python
def nth_combination(n, maxlen=4, alphabet='abc'):
"""
>>> print ','.join(nth_combination(n, 1, 'abc') ... | 1 | 2009-01-27T12:15:51Z | [
"python",
"loops",
"for-loop",
"nested-loops"
] |
Beginner-level Python threading problems | 482,263 | <p>As someone new to GUI development in Python (with pyGTK), I've just started learning about threading. To test out my skills, I've written a simple little GTK interface with a start/stop button. The goal is that when it is clicked, a thread starts that quickly increments a number in the text box, while keeping the GU... | 7 | 2009-01-27T03:38:45Z | 482,369 | <p>Generally it's better to avoid threads when you can. It's very difficult to write a threaded application correctly, and even more difficult to know you got it right. Since you're writing a GUI application, it's easier for you to visualize how to do so, since you already have to write your application within an async... | 3 | 2009-01-27T05:10:24Z | [
"python",
"multithreading",
"pygtk"
] |
Beginner-level Python threading problems | 482,263 | <p>As someone new to GUI development in Python (with pyGTK), I've just started learning about threading. To test out my skills, I've written a simple little GTK interface with a start/stop button. The goal is that when it is clicked, a thread starts that quickly increments a number in the text box, while keeping the GU... | 7 | 2009-01-27T03:38:45Z | 482,471 | <p>You can't restart a stopped thread object; don't try. Instead, create a new instance of the object if you want to restart it after it's truly stopped and joined.</p>
| 1 | 2009-01-27T06:24:06Z | [
"python",
"multithreading",
"pygtk"
] |
Beginner-level Python threading problems | 482,263 | <p>As someone new to GUI development in Python (with pyGTK), I've just started learning about threading. To test out my skills, I've written a simple little GTK interface with a start/stop button. The goal is that when it is clicked, a thread starts that quickly increments a number in the text box, while keeping the GU... | 7 | 2009-01-27T03:38:45Z | 487,110 | <p>Threading with PyGTK is bit tricky if you want to do it right. Basically, you should not update GUI from within any other thread than main thread (common limitation in GUI libs). Usually this is done in PyGTK using mechanism of queued messages (for communication between workers and GUI) which are read periodically u... | 9 | 2009-01-28T10:13:37Z | [
"python",
"multithreading",
"pygtk"
] |
Beginner-level Python threading problems | 482,263 | <p>As someone new to GUI development in Python (with pyGTK), I've just started learning about threading. To test out my skills, I've written a simple little GTK interface with a start/stop button. The goal is that when it is clicked, a thread starts that quickly increments a number in the text box, while keeping the GU... | 7 | 2009-01-27T03:38:45Z | 491,793 | <p>I've played with different tools to help clean up the work with threads, idle processing, etc.</p>
<p>make_idle is a function decorator that allows you to run a task in the background cooperatively. This is a good middle ground between something short enough to run once in the UI thread and not affect the responsi... | 0 | 2009-01-29T14:28:03Z | [
"python",
"multithreading",
"pygtk"
] |
Beginner-level Python threading problems | 482,263 | <p>As someone new to GUI development in Python (with pyGTK), I've just started learning about threading. To test out my skills, I've written a simple little GTK interface with a start/stop button. The goal is that when it is clicked, a thread starts that quickly increments a number in the text box, while keeping the GU... | 7 | 2009-01-27T03:38:45Z | 504,021 | <p>I haven't looked in detail on your code. But I see two solutions to your problem:</p>
<p>Don't use threads at all. Instead use a timeout, like this:</p>
<pre><code>import gobject
i = 0
def do_print():
global i
print i
i += 1
if i == 10:
main_loop.quit()
return False
return True... | 0 | 2009-02-02T17:18:43Z | [
"python",
"multithreading",
"pygtk"
] |
Parsing a file with column data in Python | 482,405 | <p>I have a file that contains the symbol table <code>details.Its</code> in the form of rows and columns.</p>
<p>I need to extract first and last column.</p>
<p>How can I do that?</p>
| -4 | 2009-01-27T05:38:38Z | 482,427 | <p>What type of delimiter are you using? That is, what separates your columns?</p>
<p>I'll assume you're using comma delimiters, like so:</p>
<pre><code>col1, col2, col3
col11, col12, col13
col21, col22, col23
col31, col32, col33
</code></pre>
<p>The following code will parse it and print the first and last colum... | 4 | 2009-01-27T05:53:05Z | [
"python",
"file",
"parsing"
] |
Parsing a file with column data in Python | 482,405 | <p>I have a file that contains the symbol table <code>details.Its</code> in the form of rows and columns.</p>
<p>I need to extract first and last column.</p>
<p>How can I do that?</p>
| -4 | 2009-01-27T05:38:38Z | 482,720 | <p>The most convenient way of parsing tables written to text files is using the <a href="http://docs.python.org/library/csv.html" rel="nofollow">csv module</a>. It supports any delimiter and is more convenient to use than manual line-by-line parsing. Example:</p>
<pre><code>import csv
def get_first_and_last_column(fi... | 4 | 2009-01-27T09:05:53Z | [
"python",
"file",
"parsing"
] |
Parsing a file with column data in Python | 482,405 | <p>I have a file that contains the symbol table <code>details.Its</code> in the form of rows and columns.</p>
<p>I need to extract first and last column.</p>
<p>How can I do that?</p>
| -4 | 2009-01-27T05:38:38Z | 482,907 | <p><a href="http://docs.python.org/library/csv">csv</a> module is the easier way.
You can use any separator with this code:</p>
<pre><code>import csv
def import_text(filename, separator):
for line in csv.reader(open(filename), delimiter=separator,
skipinitialspace=True):
if lin... | 12 | 2009-01-27T10:33:39Z | [
"python",
"file",
"parsing"
] |
Parsing a file with column data in Python | 482,405 | <p>I have a file that contains the symbol table <code>details.Its</code> in the form of rows and columns.</p>
<p>I need to extract first and last column.</p>
<p>How can I do that?</p>
| -4 | 2009-01-27T05:38:38Z | 13,966,913 | <p>According to the update, columns are seperated with space. So it would be:</p>
<pre><code>rawfile = open('details.Its', 'r')
table = [line.rstrip().split() for line in rawfile.readlines()]
newtable = [[line[0]]+[line[-1]] for line in table]
print(newtable)
</code></pre>
| 0 | 2012-12-20T07:06:09Z | [
"python",
"file",
"parsing"
] |
How do I convert a string to a double in Python? | 482,410 | <p>I would like to know how to convert a string containing digits to a double.</p>
| 89 | 2009-01-27T05:40:38Z | 482,423 | <pre><code>>>> x = "2342.34"
>>> float(x)
2342.3400000000001
</code></pre>
<p>There you go. Use float (which is almost always a C double).</p>
| 144 | 2009-01-27T05:49:18Z | [
"python"
] |
How do I convert a string to a double in Python? | 482,410 | <p>I would like to know how to convert a string containing digits to a double.</p>
| 89 | 2009-01-27T05:40:38Z | 6,385,389 | <p>The decimal operator might be more in line with what you are looking for:</p>
<pre><code>>>> from decimal import Decimal
>>> x = "234243.434"
>>> print Decimal(x)
234243.434
</code></pre>
| 25 | 2011-06-17T11:56:28Z | [
"python"
] |
ORM (object relational manager) solution with multiple programming language support | 482,612 | <p>Is there a good ORM (object relational manager) solution that can use the same database from C++, C#, Python?</p>
<p>It could also be multiple solutions, e.g. one per language, as long as they can can access the same database and use the same schema.</p>
<p>Multi platform support is also needed.</p>
<h2>Clarifica... | 5 | 2009-01-27T08:10:48Z | 482,653 | <p>With SQLAlchemy, you can use reflection to get the schema, so it should work with any of the supported engines.</p>
<p>I've used this to migrate data from an old SQLite to Postgres.</p>
| 1 | 2009-01-27T08:37:53Z | [
"c#",
"c++",
"python",
"orm"
] |
ORM (object relational manager) solution with multiple programming language support | 482,612 | <p>Is there a good ORM (object relational manager) solution that can use the same database from C++, C#, Python?</p>
<p>It could also be multiple solutions, e.g. one per language, as long as they can can access the same database and use the same schema.</p>
<p>Multi platform support is also needed.</p>
<h2>Clarifica... | 5 | 2009-01-27T08:10:48Z | 496,166 | <p>We have an O/RM that has C++ and C# (actually COM) bindings (in FOST.3) and we're putting together the Python bindings which are new in version 4 together with Linux and Mac support.</p>
| 0 | 2009-01-30T16:34:06Z | [
"c#",
"c++",
"python",
"orm"
] |
ORM (object relational manager) solution with multiple programming language support | 482,612 | <p>Is there a good ORM (object relational manager) solution that can use the same database from C++, C#, Python?</p>
<p>It could also be multiple solutions, e.g. one per language, as long as they can can access the same database and use the same schema.</p>
<p>Multi platform support is also needed.</p>
<h2>Clarifica... | 5 | 2009-01-27T08:10:48Z | 788,935 | <p>I know <a href="http://www.remobjects.com/da.aspx" rel="nofollow">DataAbstract</a> for Pascal, C# and soon for objective C for Mac and Iphone but no Python support.</p>
| 1 | 2009-04-25T13:35:20Z | [
"c#",
"c++",
"python",
"orm"
] |
How come my class is behaving like a static class? | 483,072 | <p>i have a module (a single .py file, actually), with a class called HashedDir.</p>
<p>when i import the file and instanciate 2 instances of that class, when i check the object's fields they're always the same, even if the two objects should be different.</p>
<p>Eg:</p>
<pre><code> h1 = HashedDir('/path/to/dir')
p... | 0 | 2009-01-27T11:36:21Z | 483,123 | <p>Is it fileList you're talking about? You have it as a class variable, to make it an instance variable you need to do:</p>
<pre><code>self.fileList = {'files': [], 'dirs': []}
</code></pre>
<p>in you __ init __ function.</p>
| 6 | 2009-01-27T11:53:11Z | [
"python"
] |
How come my class is behaving like a static class? | 483,072 | <p>i have a module (a single .py file, actually), with a class called HashedDir.</p>
<p>when i import the file and instanciate 2 instances of that class, when i check the object's fields they're always the same, even if the two objects should be different.</p>
<p>Eg:</p>
<pre><code> h1 = HashedDir('/path/to/dir')
p... | 0 | 2009-01-27T11:36:21Z | 483,137 | <p>If you declare your variables outside a class method, inside the body of the class, they will become 'class variables' and be common to all class instances. To get instance variables, declare them inside the <strong>init</strong> function and bind them to 'self', the handler for the current instance.</p>
| 1 | 2009-01-27T12:00:36Z | [
"python"
] |
How come my class is behaving like a static class? | 483,072 | <p>i have a module (a single .py file, actually), with a class called HashedDir.</p>
<p>when i import the file and instanciate 2 instances of that class, when i check the object's fields they're always the same, even if the two objects should be different.</p>
<p>Eg:</p>
<pre><code> h1 = HashedDir('/path/to/dir')
p... | 0 | 2009-01-27T11:36:21Z | 483,158 | <p>It might be useful if you could post a full working (or failing!) example.</p>
<p>If I do what I think is necessary (i.e., wrap this in Class HashedDir(object): and set self.fileList = {'files': [], 'dirs': []} inside <strong>init</strong> then it does seem to work.</p>
<p>Which items are you referring to as self.... | 0 | 2009-01-27T12:05:52Z | [
"python"
] |
How come my class is behaving like a static class? | 483,072 | <p>i have a module (a single .py file, actually), with a class called HashedDir.</p>
<p>when i import the file and instanciate 2 instances of that class, when i check the object's fields they're always the same, even if the two objects should be different.</p>
<p>Eg:</p>
<pre><code> h1 = HashedDir('/path/to/dir')
p... | 0 | 2009-01-27T11:36:21Z | 483,170 | <p>There are two kinds of variables in a class:</p>
<ul>
<li><p>class variables, defined at the class level, and common to all instances</p></li>
<li><p>instance variables, defined within a class method (usually <code>__init__</code>) and qualified by the instance (usually <code>self.</code>).</p></li>
</ul>
<p>Examp... | 10 | 2009-01-27T12:11:26Z | [
"python"
] |
How come my class is behaving like a static class? | 483,072 | <p>i have a module (a single .py file, actually), with a class called HashedDir.</p>
<p>when i import the file and instanciate 2 instances of that class, when i check the object's fields they're always the same, even if the two objects should be different.</p>
<p>Eg:</p>
<pre><code> h1 = HashedDir('/path/to/dir')
p... | 0 | 2009-01-27T11:36:21Z | 483,584 | <p>Things declared in a <code>class</code> block are class attributes, and class attributes are also accessible through the instance. (This principle, in fact, is how methods are bound.) Not only that, but default arguments for a function are only evaluated when the function is defined. So, to give an example illustrat... | 2 | 2009-01-27T14:27:15Z | [
"python"
] |
How come my class is behaving like a static class? | 483,072 | <p>i have a module (a single .py file, actually), with a class called HashedDir.</p>
<p>when i import the file and instanciate 2 instances of that class, when i check the object's fields they're always the same, even if the two objects should be different.</p>
<p>Eg:</p>
<pre><code> h1 = HashedDir('/path/to/dir')
p... | 0 | 2009-01-27T11:36:21Z | 484,081 | <p>As others have pointed out, your problem is that fileList is a class variable which you are mutating.</p>
<p>However its worth noting another potential pitfall in your code that could lead to a similar problem (though it doesn't in your specific example):</p>
<pre><code>def __init__(self, rootDir, ignoreList=[]):
... | 1 | 2009-01-27T16:25:41Z | [
"python"
] |
How to stop a Python script without error messages on the shell? | 483,208 | <p>I want to stop a Python script on seeing an error message.<br>
I dont want any error message on shell like exit().<br>
How to do it ???</p>
| -1 | 2009-01-27T12:24:42Z | 483,243 | <p>When you send <kbd>CTRL+C</kbd> to a Python script, it raises the <code>KeyboardInterrupt</code> exception, so you can do something like</p>
<pre><code>try:
... Work goes here ...
except KeyboardInterrupt:
sys.exit(0)
</code></pre>
| 9 | 2009-01-27T12:35:43Z | [
"python",
"error-handling"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 483,680 | <p>Try this:</p>
<pre><code>inv_map = dict(zip(my_map.values(), my_map.keys()))
</code></pre>
<p>(Note that <a href="https://docs.python.org/library/stdtypes.html#dictionary-view-objects" rel="nofollow">the Python docs on dictionary views</a> explicitly guarantee that <code>.keys()</code> and <code>.values()</code> h... | 18 | 2009-01-27T14:49:46Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 483,685 | <p>Assuming that the values in the dict are unique:</p>
<pre><code>dict((v, k) for k, v in my_map.iteritems())
</code></pre>
| 144 | 2009-01-27T14:50:22Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 483,833 | <p>For Python 2.7.x</p>
<pre><code>inv_map = {v: k for k, v in my_map.iteritems()}
</code></pre>
<p>For Python 3+:</p>
<pre><code>inv_map = {v: k for k, v in my_map.items()}
</code></pre>
| 352 | 2009-01-27T15:24:56Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 485,368 | <p>If the values in <code>my_map</code> aren't unique:</p>
<pre><code>inv_map = {}
for k, v in my_map.iteritems():
inv_map[v] = inv_map.get(v, [])
inv_map[v].append(k)
</code></pre>
| 67 | 2009-01-27T21:33:26Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 1,679,702 | <pre><code>def inverse_mapping(f):
return f.__class__(map(reversed, f.items()))
</code></pre>
| 18 | 2009-11-05T10:41:30Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 2,659,877 | <p>If the values aren't unique, and you're a little hardcore:</p>
<pre><code>inv_map = dict(
(v, [k for (k, xx) in filter(lambda (key, value): value == v, my_map.items())])
for v in set(my_map.values())
)
</code></pre>
<p>Especially for a large dict, note that this solution is far less efficient than the ans... | 4 | 2010-04-17T20:14:06Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 4,071,647 | <p>For all kinds of dictionary, no matter if they don't have unique values to use as keys, you can create a list of keys for each value</p>
<pre><code>inv_map = {v: inv_map.get(v, []) + [k] for k,v in my_map.items()}
</code></pre>
| -1 | 2010-11-01T17:55:53Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 13,057,382 | <p>This expands upon the answer <a href="http://stackoverflow.com/questions/483666/python-reverse-inverse-a-mapping/485368#485368">Python reverse / inverse a mapping</a>, applying to when the values in the dict aren't unique.</p>
<pre><code>class ReversibleDict(dict):
def reversed(self):
"""
Retur... | 3 | 2012-10-24T20:40:19Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 15,910,711 | <p>In addition to the other functions suggested above, if you like lambdas:</p>
<pre class="lang-py prettyprint-override"><code>invert = lambda mydict: {v:k for k, v in mydict.items()}
</code></pre>
<p>Or, you could do it this way too:</p>
<pre class="lang-py prettyprint-override"><code>invert = lambda mydict: dict(... | 5 | 2013-04-09T19:20:58Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 22,047,530 | <p>Another, more functional, way:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
dict(map(reversed, my_map.iteritems()))
</code></pre>
| 9 | 2014-02-26T16:35:03Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 22,235,665 | <p>Fast functional solution for non-bijective maps (values not unique):</p>
<pre><code>from itertools import imap, groupby
def fst(s):
return s[0]
def snd(s):
return s[1]
def inverseDict(d):
"""
input d: a -> b
output : b -> set(a)
"""
return {
v : set(imap(fst, kv_iter))
... | 0 | 2014-03-06T20:50:11Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 24,952,468 | <p>Try this for python 2.7/3.x</p>
<pre><code>inv_map={};
for i in my_map:
inv_map[my_map[i]]=i
print inv_map
</code></pre>
| 1 | 2014-07-25T09:31:58Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 26,016,809 | <p>Function is symmetric for values of type list; Tuples are coverted to lists when performing reverse_dict(reverse_dict(dictionary))</p>
<pre><code>def reverse_dict(dictionary):
reverse_dict = {}
for key, value in dictionary.iteritems():
if not isinstance(value, (list, tuple)):
value = [va... | 0 | 2014-09-24T12:23:00Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 26,082,413 | <p>I think the best way to do this is to define a class. Here is an implementation of a "symmetric dictionary":</p>
<pre><code>class SymDict:
def __init__(self):
self.aToB = {}
self.bToA = {}
def assocAB(self, a, b):
# Stores and returns a tuple (a,b) of overwritten bindings
cu... | 2 | 2014-09-28T06:50:44Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 33,900,957 | <p>if the items are not unique try this:</p>
<pre><code> dict={}
dict1={}
num=int(raw_input(" how many numbers in dict?--> "))
for i in range (0,num):
key=raw_input(" enter key --> ")
value=raw_input("enter value --> ")
dict[key]=value
keys=dict.keys()
v... | -2 | 2015-11-24T18:17:03Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 34,688,689 | <p>Since dictionaries require one unique key within the dictionary unlike values, we have to append the reversed values into a list of sort to be included within the new specific keys. </p>
<pre><code>def r_maping(dictionary):
List_z=[]
Map= {}
for z, x in dictionary.iteritems(): #iterate through the keys ... | -1 | 2016-01-09T01:26:12Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 38,081,323 | <pre><code>def dict_flip(req_dict={}):
if isinstance(req_dict,dict):
return {v:k for k,v in req_dict.items()}
return False
dict_flip({1:'a',2:'b'}) # O/P {'b':2,'a':1}
</code></pre>
| -1 | 2016-06-28T16:14:39Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 38,727,624 | <p>Not something completely different, just a bit rewritten recipe from Cookbook. It's futhermore optimized by retaining <code>setdefault</code> method, instead of each time getting it through the instance:</p>
<pre><code>def inverse(mapping):
'''
A function to inverse mapping, collecting keys with simillar va... | 1 | 2016-08-02T18:08:53Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 38,796,795 | <p>I wrote this with the help of cycle 'for' and method '.get()' and I changed the name 'map' of the dictionary to 'map1' because 'map' is a function.</p>
<pre><code>def dict_invert(map1):
inv_map = {} # new dictionary
for key in map1.keys():
inv_map[map1.get(key)] = key
return inv_map
</code></pre... | 0 | 2016-08-05T19:47:24Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
Python reverse / invert a mapping | 483,666 | <p>Given a dictionary like so:</p>
<pre><code>my_map = { 'a': 1, 'b':2 }
</code></pre>
<p>How can one invert this map to get:</p>
<pre><code>inv_map = { 1: 'a', 2: 'b' }
</code></pre>
<p><strong>EDITOR NOTE: <code>map</code> changed to <code>my_map</code> to avoid conflicts with the built-in function, <code>map</co... | 269 | 2009-01-27T14:46:09Z | 39,441,242 | <p>Using <a href="https://docs.python.org/2/library/functions.html#zip" rel="nofollow">zip</a></p>
<pre><code>inv_map = dict(zip(my_map.values(), my_map.keys()))
</code></pre>
| 0 | 2016-09-11T22:26:46Z | [
"python",
"dictionary",
"mapping",
"inverse"
] |
calling methods on an instance with getattr [ python ] | 484,220 | <p>I was trying to write some code that would check if an item has some attributes , and to call them . I tried to do that with getattr , but the modifications wouldn't be permanent . I made a "dummy" class to check upon this .
Here is the code I used for the class :</p>
<pre><code>
class X: ... | 1 | 2009-01-27T16:57:09Z | 484,227 | <p>You need to do something like</p>
<pre><code>class X:
def __init__(self):
self._value = 90
def _get(self):
return self._value
def _set(self, value):
self._value = value
value = property(_get, _set)
</code></pre>
<p>Note that the "interna... | 8 | 2009-01-27T16:59:14Z | [
"python",
"dynamic",
"attributes",
"properties"
] |
calling methods on an instance with getattr [ python ] | 484,220 | <p>I was trying to write some code that would check if an item has some attributes , and to call them . I tried to do that with getattr , but the modifications wouldn't be permanent . I made a "dummy" class to check upon this .
Here is the code I used for the class :</p>
<pre><code>
class X: ... | 1 | 2009-01-27T16:57:09Z | 484,246 | <pre><code>getattr(x,"value=",99)
</code></pre>
<p>returns 99 because <code>x</code> has no attribute "value=" (note the equals sign), so getattr returns the supplied default (99).</p>
| 2 | 2009-01-27T17:03:30Z | [
"python",
"dynamic",
"attributes",
"properties"
] |
Problem with encoding in Django templates | 484,338 | <p>I'm having problems using {% ifequal s1 "some text" %} to compare strings with extended characters in Django templates. When string s1 contains ascii characters >127, I get exceptions in the template rendering. What am I doing wrong? I'm using UTF-8 coding throughout the rest of application in both the data, templat... | 5 | 2009-01-27T17:23:20Z | 484,358 | <p>Sometimes there's nothing like describing a problem to someone else to help you solve it. :) I should have marked the Python strings as Unicode like this and everything works now:</p>
<pre><code>def test(request):
return render_to_response("test.html", {
"s1": u"dados... | 8 | 2009-01-27T17:29:17Z | [
"python",
"django",
"unicode",
"internationalization",
"django-templates"
] |
StaticText items disappear in wx.StaticBox | 484,389 | <p>I'm creating a staticbox and a staticboxsizer in a vertical sizer. Everything works fine for me, but not on the customer's environment. </p>
<p>Everything in the staticbox is displayed, but labels. snippet below shows how i construct the staticboxsizer. </p>
<pre><code> sbox2 = wx.StaticBox(self, wx.ID_ANY, 'CH... | 1 | 2009-01-27T17:38:10Z | 491,335 | <p>The source code of wxStaticBox does different things in painting code, depending on whether XP themes are enabled. In the screen shot without themes everything looks OK, in the one with themes enabled the labels are missing. Could you try on your system with themes enabled, and see whether labels display OK? Or can ... | 1 | 2009-01-29T12:02:11Z | [
"python",
"wxpython",
"wxwidgets",
"boxsizer"
] |
StaticText items disappear in wx.StaticBox | 484,389 | <p>I'm creating a staticbox and a staticboxsizer in a vertical sizer. Everything works fine for me, but not on the customer's environment. </p>
<p>Everything in the staticbox is displayed, but labels. snippet below shows how i construct the staticboxsizer. </p>
<pre><code> sbox2 = wx.StaticBox(self, wx.ID_ANY, 'CH... | 1 | 2009-01-27T17:38:10Z | 496,930 | <p>comp.Component uses the main panel -ScrolledPanel- as the parent </p>
<pre><code>class MyBackground(ScrolledPanel):
def __init__(self, parent, components):
ScrolledPanel.__init__(self, parent, -1, style=wx.TAB_TRAVERSAL)
self.setFont()
comp = Components(components, self)
...
...
app = w... | 1 | 2009-01-30T19:45:01Z | [
"python",
"wxpython",
"wxwidgets",
"boxsizer"
] |
How would you determine where each property and method of a Python class is defined? | 484,890 | <p>Given an instance of some class in Python, it would be useful to be able to determine which line of source code <em>defined</em> each method and property (e.g. to implement [1]). For example, given a module ab.py</p>
<pre><code>class A(object):
z = 1
q = 2
def y(self): pass
def x(self): pass
class ... | 3 | 2009-01-27T19:37:19Z | 484,947 | <p>You are looking for the <a href="http://docs.python.org/library/inspect.html" rel="nofollow">inspect</a> module, specifically <code>inspect.getsourcefile()</code> and <code>inspect.getsourcelines()</code>. For example</p>
<p>a.py:</p>
<pre><code>class Hello(object):
def say(self):
print 1
>>> ... | 1 | 2009-01-27T19:52:26Z | [
"python",
"introspection",
"plone",
"python-datamodel"
] |
How would you determine where each property and method of a Python class is defined? | 484,890 | <p>Given an instance of some class in Python, it would be useful to be able to determine which line of source code <em>defined</em> each method and property (e.g. to implement [1]). For example, given a module ab.py</p>
<pre><code>class A(object):
z = 1
q = 2
def y(self): pass
def x(self): pass
class ... | 3 | 2009-01-27T19:37:19Z | 484,966 | <p>This is more-or-less impossible without static analysis, and even then, it won't always work. You can get the line where a function was defined and in which file by examining its code object, but beyond that, there's not much you can do. The <code>inspect</code> module can help with this. So:</p>
<pre><code>import ... | 2 | 2009-01-27T19:56:49Z | [
"python",
"introspection",
"plone",
"python-datamodel"
] |
How would you determine where each property and method of a Python class is defined? | 484,890 | <p>Given an instance of some class in Python, it would be useful to be able to determine which line of source code <em>defined</em> each method and property (e.g. to implement [1]). For example, given a module ab.py</p>
<pre><code>class A(object):
z = 1
q = 2
def y(self): pass
def x(self): pass
class ... | 3 | 2009-01-27T19:37:19Z | 485,550 | <p>You are looking for the undocumented function <code>inspect.classify_class_attrs(cls)</code>. Pass it a class and it will return a list of tuples <code>('name', 'kind' e.g. 'method' or 'data', defining class, property)</code>. If you need information on absolutely everything in a specific instance you'll have to do ... | 1 | 2009-01-27T22:11:53Z | [
"python",
"introspection",
"plone",
"python-datamodel"
] |
Does anyone have example code of using scipy.stats.distributions? | 485,076 | <p>I am struggling to figure out how to use the scipy.distributions package and wondered if anyone could post some example code for me. It appears to do everything I need, I just can't figure out how to use it.</p>
<p>I need to generate two distributions, one log-normal and one poisson. I know the variance and lambd... | 9 | 2009-01-27T20:24:27Z | 485,233 | <p>I assume you mean the distributions in <code>scipy.stats</code>. To create a distribution, generate random variates and calculate the pdf:</p>
<p>Python 2.5.1 (r251:54863, Feb 4 2008, 21:48:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.</p>... | 6 | 2009-01-27T21:00:25Z | [
"python",
"scipy"
] |
Does anyone have example code of using scipy.stats.distributions? | 485,076 | <p>I am struggling to figure out how to use the scipy.distributions package and wondered if anyone could post some example code for me. It appears to do everything I need, I just can't figure out how to use it.</p>
<p>I need to generate two distributions, one log-normal and one poisson. I know the variance and lambd... | 9 | 2009-01-27T20:24:27Z | 1,182,294 | <p>Here's some sample code: <a href="http://www.johndcook.com/blog/2009/07/20/probability-distributions-scipy/" rel="nofollow">Probability distributions in SciPy</a></p>
| 3 | 2009-07-25T15:20:48Z | [
"python",
"scipy"
] |
Why aren't all the names in dir(x) valid for attribute access? | 485,095 | <p>Why would a coder stuff things into <code>__dict__</code> that can't be used for attribute access? For example, in my Plone instance, <code>dir(portal)</code> includes <code>index_html</code>, but <code>portal.index_html</code> raises AttributeError. This is also true for the <code>__class__</code> attribute of <cod... | 3 | 2009-01-27T20:30:47Z | 485,624 | <p>I don't know about Plone, so the following is general.</p>
<p>From <a href="http://docs.python.org/library/functions.html#dir" rel="nofollow">the docs</a> of <code>dir</code>:</p>
<blockquote>
<p>If the object has a method named
<code>__dir__()</code>, this method will be called and must return the list of
a... | 2 | 2009-01-27T22:30:02Z | [
"python",
"introspection",
"python-datamodel"
] |
Why do I get TypeError: can't multiply sequence by non-int of type 'float'? | 485,789 | <p>I am typing to get a sale amount (by input) to be multiplied by a defined sales tax (0.08) and then have it print the total amount (sales tax times sale amount).</p>
<p>I run into this error. Anyone know what could be wrong or have any suggestions? </p>
<pre><code>salesAmount = raw_input (["Insert sale amount here... | 33 | 2009-01-27T23:11:02Z | 485,797 | <p>The problem is that salesAmount is being set to a string. If you enter the variable in the python interpreter and hit enter, you'll see the value entered surrounded by quotes. For example, if you entered 56.95 you'd see:</p>
<pre><code>>>> sales_amount = raw_input("[Insert sale amount]: ")
[Insert sale a... | 2 | 2009-01-27T23:16:17Z | [
"python"
] |
Why do I get TypeError: can't multiply sequence by non-int of type 'float'? | 485,789 | <p>I am typing to get a sale amount (by input) to be multiplied by a defined sales tax (0.08) and then have it print the total amount (sales tax times sale amount).</p>
<p>I run into this error. Anyone know what could be wrong or have any suggestions? </p>
<pre><code>salesAmount = raw_input (["Insert sale amount here... | 33 | 2009-01-27T23:11:02Z | 485,808 | <p><code>raw_input</code> returns a string (a sequence of characters). In Python, multiplying a string and a float makes no defined meaning (while multiplying a string and an integer has a meaning: <code>"AB" * 3</code> is <code>"ABABAB"</code>; how much is <code>"L" * 3.14</code> ? Please do not reply <code>"LLL|"</co... | 36 | 2009-01-27T23:19:00Z | [
"python"
] |
Why do I get TypeError: can't multiply sequence by non-int of type 'float'? | 485,789 | <p>I am typing to get a sale amount (by input) to be multiplied by a defined sales tax (0.08) and then have it print the total amount (sales tax times sale amount).</p>
<p>I run into this error. Anyone know what could be wrong or have any suggestions? </p>
<pre><code>salesAmount = raw_input (["Insert sale amount here... | 33 | 2009-01-27T23:11:02Z | 27,488,582 | <p>Maybe this will help others in the future - I had the same error while trying to multiple a float and a list of floats. The thing is that everyone here talked about multiplying a float with a string (but here all my element were floats all along) so the problem was actually using the * operator on a list.</p>
<p>Fo... | 7 | 2014-12-15T16:28:02Z | [
"python"
] |
Python shelve module question | 486,490 | <p>Does the Python shelve module have any protection built in to make sure two processes aren't writing to a file at the same time?</p>
| 6 | 2009-01-28T04:32:14Z | 486,676 | <p>The shelve module uses an underlying database package (such as dbm, <a href="http://docs.python.org/library/gdbm.html#module-gdbm" rel="nofollow">gdbm</a> or bsddb) .</p>
<p>The <a href="http://docs.python.org/library/shelve.html#restrictions" rel="nofollow"><em>restrictions</em> pragraph</a> says (my emphasis):</p... | 7 | 2009-01-28T06:38:26Z | [
"python",
"shelve"
] |
Python shelve module question | 486,490 | <p>Does the Python shelve module have any protection built in to make sure two processes aren't writing to a file at the same time?</p>
| 6 | 2009-01-28T04:32:14Z | 7,915,260 | <p>As per the top answer, it's not safe to have multiple writers to the shelve. My approach to making shelves safer is to write a wrapper that takes care of opening and accessing shelve elements. The wrapper code looks something like this:</p>
<pre><code>def open(self, mode=READONLY):
if mode is READWRITE:
... | 2 | 2011-10-27T11:31:56Z | [
"python",
"shelve"
] |
Python shelve module question | 486,490 | <p>Does the Python shelve module have any protection built in to make sure two processes aren't writing to a file at the same time?</p>
| 6 | 2009-01-28T04:32:14Z | 8,138,985 | <p>I've implemented <a href="http://stackoverflow.com/questions/486490/python-shelve-module-question/7915260#7915260">Ivo's approach</a> as a context manager, for anyone interested:</p>
<pre><code>from contextlib import contextmanager, closing
from fcntl import flock, LOCK_SH, LOCK_EX, LOCK_UN
import shelve
@contextm... | 2 | 2011-11-15T15:42:54Z | [
"python",
"shelve"
] |
Ruby equivalent of virtualenv? | 486,995 | <p>Is there something similar to the Python utility <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a>?</p>
<p>Basically it allows you to install Python packages into a sandboxed environment, so <code>easy_install django</code> doesn't go in your system-wide site-packages directory, it would go in the vir... | 126 | 2009-01-28T09:24:14Z | 487,045 | <p>I think you'll like <a href="http://github.com/nkryptic/sandbox/tree/master">sandbox</a>.</p>
| 15 | 2009-01-28T09:49:35Z | [
"python",
"ruby",
"virtualenv"
] |
Ruby equivalent of virtualenv? | 486,995 | <p>Is there something similar to the Python utility <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a>?</p>
<p>Basically it allows you to install Python packages into a sandboxed environment, so <code>easy_install django</code> doesn't go in your system-wide site-packages directory, it would go in the vir... | 126 | 2009-01-28T09:24:14Z | 3,801,789 | <p><a href="http://rvm.io/">RVM</a> works closer to how virtualenv works since it lets you sandbox different ruby versions and their gems, etc.</p>
| 63 | 2010-09-27T07:20:31Z | [
"python",
"ruby",
"virtualenv"
] |
Ruby equivalent of virtualenv? | 486,995 | <p>Is there something similar to the Python utility <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a>?</p>
<p>Basically it allows you to install Python packages into a sandboxed environment, so <code>easy_install django</code> doesn't go in your system-wide site-packages directory, it would go in the vir... | 126 | 2009-01-28T09:24:14Z | 12,663,154 | <p>No one seems to have mentioned <a href="http://rbenv.org/">rbenv</a>.</p>
| 14 | 2012-09-30T16:58:20Z | [
"python",
"ruby",
"virtualenv"
] |
Ruby equivalent of virtualenv? | 486,995 | <p>Is there something similar to the Python utility <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a>?</p>
<p>Basically it allows you to install Python packages into a sandboxed environment, so <code>easy_install django</code> doesn't go in your system-wide site-packages directory, it would go in the vir... | 126 | 2009-01-28T09:24:14Z | 12,663,612 | <p>Neither sandbox, RVM, nor rbenv manage the versions of your app's gem dependencies. The tool for that is <a href="http://gembundler.com/v1.2/rationale.html">bundler</a>.</p>
<ul>
<li>use a <a href="http://gembundler.com/v0.9/gemfile.html">Gemfile</a> as your application's dependency declaration</li>
<li>use <code>b... | 34 | 2012-09-30T17:57:19Z | [
"python",
"ruby",
"virtualenv"
] |
Ruby equivalent of virtualenv? | 486,995 | <p>Is there something similar to the Python utility <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a>?</p>
<p>Basically it allows you to install Python packages into a sandboxed environment, so <code>easy_install django</code> doesn't go in your system-wide site-packages directory, it would go in the vir... | 126 | 2009-01-28T09:24:14Z | 13,307,346 | <p>I'll mention the way I do this with Bundler (which I use with RVM - RVM to manage the rubies and a default set of global gems, Bundler to handle project specific gems)</p>
<pre><code>bundler install --binstubs --path vendor
</code></pre>
<p>Running this command in the root of a project will install the gems listed... | 8 | 2012-11-09T11:33:15Z | [
"python",
"ruby",
"virtualenv"
] |
Ruby equivalent of virtualenv? | 486,995 | <p>Is there something similar to the Python utility <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a>?</p>
<p>Basically it allows you to install Python packages into a sandboxed environment, so <code>easy_install django</code> doesn't go in your system-wide site-packages directory, it would go in the vir... | 126 | 2009-01-28T09:24:14Z | 17,413,767 | <p>If you only need to install gems as non-root, try setting the <code>GEM_HOME</code> environment variable. Then just run <code>gem</code>.</p>
<p>For example:</p>
<pre><code>$ export GEM_HOME=$HOME/local/gems
$ gem install rhc
</code></pre>
| 12 | 2013-07-01T21:10:18Z | [
"python",
"ruby",
"virtualenv"
] |
Ruby equivalent of virtualenv? | 486,995 | <p>Is there something similar to the Python utility <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a>?</p>
<p>Basically it allows you to install Python packages into a sandboxed environment, so <code>easy_install django</code> doesn't go in your system-wide site-packages directory, it would go in the vir... | 126 | 2009-01-28T09:24:14Z | 33,823,445 | <p>I recommend <a href="https://github.com/direnv/direnv" rel="nofollow">direnv</a>. It is an environment switcher for the shell.</p>
<p>Before each prompt it checks for the existence of an ".envrc" file in the current and parent directories. If the file exists (and authorized), it is loaded into a bash sub-shell and ... | 1 | 2015-11-20T09:42:48Z | [
"python",
"ruby",
"virtualenv"
] |
How do I specify input and output data types in python comments? | 487,184 | <p>I have seen several standards for writing comments about the kind of data a function expects and returns in Python. Is there a consensus on which one is best-practice? </p>
<p>Is the new functionality in <a href="http://www.python.org/dev/peps/pep-3107/">http://www.python.org/dev/peps/pep-3107/</a> something I shou... | 11 | 2009-01-28T10:40:31Z | 487,203 | <p>Function annotations are not for a specific use, they can be used for anything.</p>
<p>Tools can be written to extract information from the annotations and do anything you want, including checking types or generating documentation. But python itself does not do anything with the information. You could use to a comp... | 13 | 2009-01-28T10:44:32Z | [
"python",
"documentation",
"comments",
"types"
] |
How do I specify input and output data types in python comments? | 487,184 | <p>I have seen several standards for writing comments about the kind of data a function expects and returns in Python. Is there a consensus on which one is best-practice? </p>
<p>Is the new functionality in <a href="http://www.python.org/dev/peps/pep-3107/">http://www.python.org/dev/peps/pep-3107/</a> something I shou... | 11 | 2009-01-28T10:40:31Z | 487,306 | <p>If you use <a href="http://epydoc.sourceforge.net/">epydoc</a> to produce API documentation, you have three choices.</p>
<ul>
<li><p>Epytext.</p></li>
<li><p>ReStructuredText, RST.</p></li>
<li><p>JavaDoc notation, which looks a bit like epytext.</p></li>
</ul>
<p>I recommend RST because it works well with <a href... | 7 | 2009-01-28T11:30:54Z | [
"python",
"documentation",
"comments",
"types"
] |
Reducing Django Memory Usage. Low hanging fruit? | 487,224 | <p>My memory usage increases over time and restarting Django is not kind to users.</p>
<p>I am unsure how to go about profiling the memory usage but some tips on how to start measuring would be useful.</p>
<p>I have a feeling that there are some simple steps that could produce big gains. Ensuring 'debug' is set to 'F... | 127 | 2009-01-28T10:52:19Z | 487,261 | <p>Make sure you are not keeping global references to data. That prevents the python garbage collector from releasing the memory.</p>
<p>Don't use <code>mod_python</code>. It loads an interpreter inside apache. If you need to use apache, use <a href="http://code.google.com/p/modwsgi/"><code>mod_wsgi</code></a> instead... | 44 | 2009-01-28T11:11:14Z | [
"python",
"django",
"profiling",
"memory-management",
"mod-python"
] |
Reducing Django Memory Usage. Low hanging fruit? | 487,224 | <p>My memory usage increases over time and restarting Django is not kind to users.</p>
<p>I am unsure how to go about profiling the memory usage but some tips on how to start measuring would be useful.</p>
<p>I have a feeling that there are some simple steps that could produce big gains. Ensuring 'debug' is set to 'F... | 127 | 2009-01-28T10:52:19Z | 488,230 | <p>In addition to not keeping around global references to large data objects, try to avoid loading large datasets into memory at all wherever possible.</p>
<p>Switch to mod_wsgi in daemon mode, and use Apache's worker mpm instead of prefork. This latter step can allow you to serve many more concurrent users with much... | 4 | 2009-01-28T16:13:18Z | [
"python",
"django",
"profiling",
"memory-management",
"mod-python"
] |
Reducing Django Memory Usage. Low hanging fruit? | 487,224 | <p>My memory usage increases over time and restarting Django is not kind to users.</p>
<p>I am unsure how to go about profiling the memory usage but some tips on how to start measuring would be useful.</p>
<p>I have a feeling that there are some simple steps that could produce big gains. Ensuring 'debug' is set to 'F... | 127 | 2009-01-28T10:52:19Z | 497,103 | <p>Another plus for mod_wsgi: set a <code>maximum-requests</code> parameter in your <code>WSGIDaemonProcess</code> directive and mod_wsgi will restart the daemon process every so often. There should be no visible effect for the user, other than a slow page load the first time a fresh process is hit, as it'll be loading... | 3 | 2009-01-30T20:23:11Z | [
"python",
"django",
"profiling",
"memory-management",
"mod-python"
] |
Reducing Django Memory Usage. Low hanging fruit? | 487,224 | <p>My memory usage increases over time and restarting Django is not kind to users.</p>
<p>I am unsure how to go about profiling the memory usage but some tips on how to start measuring would be useful.</p>
<p>I have a feeling that there are some simple steps that could produce big gains. Ensuring 'debug' is set to 'F... | 127 | 2009-01-28T10:52:19Z | 500,101 | <p>Webfaction actually has <a href="http://blog.webfaction.com/tips-to-keep-your-django-mod-python-memory-usage-down" rel="nofollow">some tips</a> for keeping django memory usage down.</p>
<p>The major points:</p>
<ul>
<li>Make sure debug is set to false (you already know that).</li>
<li>Use "ServerLimit" in your apa... | 4 | 2009-02-01T03:15:41Z | [
"python",
"django",
"profiling",
"memory-management",
"mod-python"
] |
Reducing Django Memory Usage. Low hanging fruit? | 487,224 | <p>My memory usage increases over time and restarting Django is not kind to users.</p>
<p>I am unsure how to go about profiling the memory usage but some tips on how to start measuring would be useful.</p>
<p>I have a feeling that there are some simple steps that could produce big gains. Ensuring 'debug' is set to 'F... | 127 | 2009-01-28T10:52:19Z | 501,501 | <p>If you are running under mod_wsgi, and presumably spawning since it is WSGI compliant, you can use <a href="http://pypi.python.org/pypi/Dozer">Dozer</a> to look at your memory usage.</p>
<p>Under mod_wsgi just add this at the bottom of your WSGI script:</p>
<pre><code>from dozer import Dozer
application = Dozer(ap... | 25 | 2009-02-01T20:18:57Z | [
"python",
"django",
"profiling",
"memory-management",
"mod-python"
] |
Reducing Django Memory Usage. Low hanging fruit? | 487,224 | <p>My memory usage increases over time and restarting Django is not kind to users.</p>
<p>I am unsure how to go about profiling the memory usage but some tips on how to start measuring would be useful.</p>
<p>I have a feeling that there are some simple steps that could produce big gains. Ensuring 'debug' is set to 'F... | 127 | 2009-01-28T10:52:19Z | 510,074 | <p>Caches: make sure they're being flushed. Its easy for something to land in a cache, but never be GC'd because of the cache reference.</p>
<p>Swig'd code: Make sure any memory management is being done correctly, its really easy to miss these in python, especially with third party libraries</p>
<p>Monitoring: If yo... | 1 | 2009-02-04T04:31:53Z | [
"python",
"django",
"profiling",
"memory-management",
"mod-python"
] |
Reducing Django Memory Usage. Low hanging fruit? | 487,224 | <p>My memory usage increases over time and restarting Django is not kind to users.</p>
<p>I am unsure how to go about profiling the memory usage but some tips on how to start measuring would be useful.</p>
<p>I have a feeling that there are some simple steps that could produce big gains. Ensuring 'debug' is set to 'F... | 127 | 2009-01-28T10:52:19Z | 513,415 | <p>Additionally, check if you do not use any of known leakers. MySQLdb is known to leak enormous amounts of memory with Django due to bug in unicode handling. Other than that, <a href="http://github.com/robhudson/django-debug-toolbar/tree/master">Django Debug Toolbar</a> might help you to track the hogs.</p>
| 5 | 2009-02-04T21:22:05Z | [
"python",
"django",
"profiling",
"memory-management",
"mod-python"
] |
Reducing Django Memory Usage. Low hanging fruit? | 487,224 | <p>My memory usage increases over time and restarting Django is not kind to users.</p>
<p>I am unsure how to go about profiling the memory usage but some tips on how to start measuring would be useful.</p>
<p>I have a feeling that there are some simple steps that could produce big gains. Ensuring 'debug' is set to 'F... | 127 | 2009-01-28T10:52:19Z | 519,390 | <p>Here is the script I use for mod_wsgi (called wsgi.py, and put in the root off my django project):</p>
<pre><code>import os
import sys
import django.core.handlers.wsgi
from os import path
sys.stdout = open('/dev/null', 'a+')
sys.stderr = open('/dev/null', 'a+')
sys.path.append(path.join(path.dirname(__file__), '... | 3 | 2009-02-06T07:09:02Z | [
"python",
"django",
"profiling",
"memory-management",
"mod-python"
] |
Reducing Django Memory Usage. Low hanging fruit? | 487,224 | <p>My memory usage increases over time and restarting Django is not kind to users.</p>
<p>I am unsure how to go about profiling the memory usage but some tips on how to start measuring would be useful.</p>
<p>I have a feeling that there are some simple steps that could produce big gains. Ensuring 'debug' is set to 'F... | 127 | 2009-01-28T10:52:19Z | 521,918 | <p>These are the Python memory profiler solutions I'm aware of (not Django related):</p>
<ul>
<li><a href="http://guppy-pe.sourceforge.net/#Heapy">Heapy</a></li>
<li><a href="http://pysizer.8325.org/">pysizer</a> (discontinued)</li>
<li><a href="http://www.softwareverify.com/python/memory/index.html">Python Memory Val... | 14 | 2009-02-06T19:55:59Z | [
"python",
"django",
"profiling",
"memory-management",
"mod-python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.