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 |
|---|---|---|---|---|---|---|---|---|---|
Dynamic terminal printing with python | 2,122,385 | <p>Certain applications like hellanzb have a way of printing to the terminal with the appearance of dynamically refreshing data, kind of like top().</p>
<p>Whats the best method in python for doing this? I have read up on logging and curses, but don't know what to use. I am creating a reimplementation of top. If yo... | 16 | 2010-01-23T06:33:29Z | 37,713,817 | <p>As most of the answers have already stated, you really have little option on Linux but to use <code>ncurses</code>. But what if you aren't on Linux, or want something a little more high-level for creating your terminal UI?</p>
<p>I personally found the lack of a modern, cross-platform terminal API in Python frustr... | 1 | 2016-06-08T22:12:25Z | [
"python",
"terminal"
] |
Calling a midlet jar for retrieve data into a python code | 2,122,874 | <p>I have a JAR file midlet JAR file, which returns an INT value according to some input data... </p>
<p>Problem is, i need to get that INT value by calling the jar file via some python code (and send the required input data to get the result data). How can i access the functions and variables of a midlet JAR file?</p... | 2 | 2010-01-23T10:50:01Z | 2,123,609 | <p><a href="http://www.jython.org/" rel="nofollow">Jython</a> has native access to Java code, but I'm not sure if it supports MIDP.</p>
| 0 | 2010-01-23T15:17:11Z | [
"java",
"python",
"java-me"
] |
Calling a midlet jar for retrieve data into a python code | 2,122,874 | <p>I have a JAR file midlet JAR file, which returns an INT value according to some input data... </p>
<p>Problem is, i need to get that INT value by calling the jar file via some python code (and send the required input data to get the result data). How can i access the functions and variables of a midlet JAR file?</p... | 2 | 2010-01-23T10:50:01Z | 2,123,643 | <p>I don't know much about J2ME, but you might be able to use Python's <a href="http://docs.python.org/library/pipes.html" rel="nofollow">pipe</a> facility to invoke a method in the JAR, e.g. <code>java -jar myjar.jar org.package.Main param1</code>. See also the <a href="http://java.sun.com/javase/6/docs/technotes/tool... | 0 | 2010-01-23T15:30:40Z | [
"java",
"python",
"java-me"
] |
Calling a midlet jar for retrieve data into a python code | 2,122,874 | <p>I have a JAR file midlet JAR file, which returns an INT value according to some input data... </p>
<p>Problem is, i need to get that INT value by calling the jar file via some python code (and send the required input data to get the result data). How can i access the functions and variables of a midlet JAR file?</p... | 2 | 2010-01-23T10:50:01Z | 3,551,024 | <p>A MIDlet can not run in a standard desktop JVM because it needs some extra libraries. But you can use an emulator like <a href="http://www.microemu.org/" rel="nofollow">http://www.microemu.org/</a> to run the program.
How to access a specific function inside the code, call it with specific parameters and read the re... | 0 | 2010-08-23T19:34:39Z | [
"java",
"python",
"java-me"
] |
Python - uniquifying(!) dictionary keys | 2,122,880 | <p>I have data coming in from a machine (via pexpect) and I parse it using regexes into a dictionary like this </p>
<pre><code>for line in stream:
if '/' in line:
# some matching etc which results in getting the
# machine name, an interface and the data for that interface
key=str(hostname)... | 1 | 2010-01-23T10:51:16Z | 2,122,891 | <pre><code>for (lineno, line) in enumerate(stream):
if '/' in line:
# some matching etc which results in getting the
# machine name, an interface and the data for that interface
key=str(hostname)+":"+r.groups()[0][0:2]+r.groups()[2]
dict[key + ":" + lineno]=str(line[3])
</code></pre>... | 0 | 2010-01-23T10:57:02Z | [
"python",
"dictionary"
] |
Python - uniquifying(!) dictionary keys | 2,122,880 | <p>I have data coming in from a machine (via pexpect) and I parse it using regexes into a dictionary like this </p>
<pre><code>for line in stream:
if '/' in line:
# some matching etc which results in getting the
# machine name, an interface and the data for that interface
key=str(hostname)... | 1 | 2010-01-23T10:51:16Z | 2,122,896 | <p>You can create a list for each key, holding all values for that key:</p>
<pre><code>d = collections.defaultdict(list)
for line in stream:
if '/' in line:
#.....
key = str(hostname)+":"+r.groups()[0][0:2]+r.groups()[2]
value = str(line[3])
d[key].append(value)
</code></pre>
<p>E... | 4 | 2010-01-23T10:58:57Z | [
"python",
"dictionary"
] |
What is the method of doing nl2br in Genshi? | 2,123,162 | <p>hiyas. I using Genshi+Pylons.</p>
<p>please teach me, how use \n to <br/>tag in Genshi?</p>
<p>I hope to obtain the same result as "<strong>nl2br</strong>" in php to change line. <br />
Or, does not the solution exist?</p>
<p>i'm assign template to some text.</p>
<pre><code>(genshi template)
<p>${c.m... | 1 | 2010-01-23T12:44:41Z | 2,123,254 | <p>Try this:</p>
<pre><code><py:for each="line in message.split('\n')">${line}<br /></py:for>
</code></pre>
| 2 | 2010-01-23T13:21:46Z | [
"python",
"pylons",
"genshi"
] |
python threading/fork? | 2,123,269 | <p>I'm making a python script that needs to do 3 things simultaneously.
What is a good way to achieve this as do to what i've heard about the GIL i'm not so lean into using threads anymore.<br>
2 of the things that the script needs to do will be heavily active, they will have lots of work to do and then i need to have ... | 4 | 2010-01-23T13:27:09Z | 2,123,285 | <p>I think you could use the <a href="http://docs.python.org/library/multiprocessing.html" rel="nofollow">multiprocessing</a> package that has an API similar to the threading package and will allow you to get a better performance with multiple cores on a single CPU. </p>
<p>To view the gain of performance using multip... | 3 | 2010-01-23T13:33:55Z | [
"python",
"multithreading",
"multiprocess"
] |
python threading/fork? | 2,123,269 | <p>I'm making a python script that needs to do 3 things simultaneously.
What is a good way to achieve this as do to what i've heard about the GIL i'm not so lean into using threads anymore.<br>
2 of the things that the script needs to do will be heavily active, they will have lots of work to do and then i need to have ... | 4 | 2010-01-23T13:27:09Z | 2,123,513 | <p>The GIL is really only something to care about if you want to do multiprocessing, that is spread the load over several cores/processors. If that is the case, and it kinda sounds like it from your description, use multiprocessing.</p>
<p>If you just need to do three things "simultaneously" in that way that you need ... | 2 | 2010-01-23T14:47:50Z | [
"python",
"multithreading",
"multiprocess"
] |
Python, Source-Code Encoding Problem | 2,123,283 | <p>I'm using Notepad++ editor on windows with format set to ASCII,
I've read "PEP 263: Source Code Encodings" and amended my code accordingly (I think), but there are characters still printing in hex...</p>
<pre><code>#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os, sys
a_munge = [ "A", "4", "/\\", "\@", "/-\\",... | 0 | 2010-01-23T13:33:40Z | 2,123,298 | <p>Perhaps you should be using unicode literals (e.g. <code>u'â¬'</code>) instead.</p>
| 2 | 2010-01-23T13:38:25Z | [
"python",
"character-encoding"
] |
Python, Source-Code Encoding Problem | 2,123,283 | <p>I'm using Notepad++ editor on windows with format set to ASCII,
I've read "PEP 263: Source Code Encodings" and amended my code accordingly (I think), but there are characters still printing in hex...</p>
<pre><code>#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os, sys
a_munge = [ "A", "4", "/\\", "\@", "/-\\",... | 0 | 2010-01-23T13:33:40Z | 2,123,674 | <p>The line:</p>
<pre><code># -*- coding: UTF-8 -*-
</code></pre>
<p>declares that the <strong>source file</strong> is saved in UTF-8. Anything else is an error.</p>
<p>When you declare <strong>byte strings</strong> in your source code:</p>
<pre><code>e_munge = [ "E", "3", "&", "â¬", "£", "[-", "|=-", "?" ]
... | 2 | 2010-01-23T15:42:00Z | [
"python",
"character-encoding"
] |
Python, Source-Code Encoding Problem | 2,123,283 | <p>I'm using Notepad++ editor on windows with format set to ASCII,
I've read "PEP 263: Source Code Encodings" and amended my code accordingly (I think), but there are characters still printing in hex...</p>
<pre><code>#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os, sys
a_munge = [ "A", "4", "/\\", "\@", "/-\\",... | 0 | 2010-01-23T13:33:40Z | 2,125,381 | <p><code>print some_list</code> is in effect <code>print repr(some_list)</code> -- that's why you see <code>\u20ac</code> instead of a Euro character. For debugging purposes, the "unicode hex" is exactly what you need for unambiguous display of your data.</p>
<p>You appear to have perfectly OK unicode objects in your ... | 1 | 2010-01-24T00:40:53Z | [
"python",
"character-encoding"
] |
Good looking Python GUI toolkit for Snow Leopard(64 bit) | 2,123,335 | <p>I'm looking for a GUI toolkit/framework to create applications that run on Mac Snow Leopard and preferably other systems(Windows, Linux).</p>
<p>Deal breakers:</p>
<ul>
<li>X11 based</li>
<li>Non-native widgets</li>
<li>32 bit/Carbon</li>
<li>Bad Mac look and feel</li>
</ul>
<p>As far as I know Tkinter runs X11 a... | 7 | 2010-01-23T13:48:13Z | 2,123,353 | <p>Maybe PyQt works on Snow Leopard 64 bits. Look at <a href="http://mpastell.com/2009/11/24/pyqt-4-6-2-with-snow-leopard/" rel="nofollow">this link</a> and try it.</p>
| 2 | 2010-01-23T13:53:04Z | [
"python",
"user-interface",
"osx",
"osx-snow-leopard"
] |
Good looking Python GUI toolkit for Snow Leopard(64 bit) | 2,123,335 | <p>I'm looking for a GUI toolkit/framework to create applications that run on Mac Snow Leopard and preferably other systems(Windows, Linux).</p>
<p>Deal breakers:</p>
<ul>
<li>X11 based</li>
<li>Non-native widgets</li>
<li>32 bit/Carbon</li>
<li>Bad Mac look and feel</li>
</ul>
<p>As far as I know Tkinter runs X11 a... | 7 | 2010-01-23T13:48:13Z | 2,123,604 | <p>Your list doesn't specifically rule out <a href="http://developer.apple.com/cocoa/pyobjc.html" rel="nofollow">CocoaPython/PyObjC</a>, which would be completely native on Mac OS X. It wouldn't run on anything else, though,</p>
| 2 | 2010-01-23T15:14:44Z | [
"python",
"user-interface",
"osx",
"osx-snow-leopard"
] |
Good looking Python GUI toolkit for Snow Leopard(64 bit) | 2,123,335 | <p>I'm looking for a GUI toolkit/framework to create applications that run on Mac Snow Leopard and preferably other systems(Windows, Linux).</p>
<p>Deal breakers:</p>
<ul>
<li>X11 based</li>
<li>Non-native widgets</li>
<li>32 bit/Carbon</li>
<li>Bad Mac look and feel</li>
</ul>
<p>As far as I know Tkinter runs X11 a... | 7 | 2010-01-23T13:48:13Z | 2,125,594 | <p>The Apple-supplied Tk, Aqua Tk, on OS X has not been X11-based since at least OS X 10.4. Apple ships a 64-bit version of Aqua Tk in OS X 10.6 and the Tkinter in the Apple-supplied Python 2.6 is linked with it. There have been some reported problems using IDLE and other test applications with it, though. Your mileag... | 1 | 2010-01-24T02:02:14Z | [
"python",
"user-interface",
"osx",
"osx-snow-leopard"
] |
failed abstraction of variable in for loop | 2,123,408 | <p>I'm trying to make a 4x4 sudoku solver in Python (I'm only a beginner!) and while trying to define a function to clean up my code somewhat, I ran across some strange behavior I don't really understand. Apparently, there's a difference between this:</p>
<pre><code>sudoku = "0200140000230040"
sudoku = map(lambda x: ... | 2 | 2010-01-23T14:11:29Z | 2,123,434 | <p>There is a difference... they fail with two different errors!</p>
<p>The first gives me this error:</p>
<pre><code> File "test.py", line 9, in <module>
sudoku[i/4*4+k] = sudoku[i/4*4+k].translate(None, str(j+1))
TypeError: expected a character buffer object
</code></pre>
<p>The second gives me this err... | 2 | 2010-01-23T14:18:48Z | [
"python",
"function",
"sudoku"
] |
python automate ffmpeg conversion from upload directory | 2,123,435 | <p>I have a upload script done. But i need to figure out how to make a script that I can run as a daemon in python to handle the conversion part and moving the file thats converted to its final resting place. heres what I have so far for the directory watcher script:</p>
<pre><code> #!/usr/bin/python
import os
import... | 3 | 2010-01-23T14:19:48Z | 2,128,361 | <p>I don't run on Linux and have never used the inotify capabilities you are using here. I'll describe how I would do things generically.</p>
<p>In the simplest case, you need to check if there's a new file in the upload directory and when there is one, start doing the conversion notification.</p>
<p>To check if ther... | 3 | 2010-01-24T19:17:30Z | [
"python",
"ffmpeg",
"inotify"
] |
Paramiko equvalent of pipline controls and input/output pipes | 2,123,581 | <p>I need a method of paramiko based file transfer with a lightweight <a href="http://en.wikipedia.org/wiki/Secure_Shell#Version_2.0" rel="nofollow">SSH2</a> server (<a href="http://matt.ucc.asn.au/dropbear/dropbear.html" rel="nofollow">dropbear</a>) which has no support for <a href="http://en.wikipedia.org/wiki/Secure... | 5 | 2010-01-23T15:07:07Z | 2,124,133 | <p>If the limitation, as you say, is only in your client, you can easily implement a SFTP client directly with paramiko -- e.g., look at this <a href="http://commandline.org.uk/python/sftp-python/" rel="nofollow">example</a> code.</p>
| 1 | 2010-01-23T18:13:31Z | [
"python",
"file",
"transfer",
"paramiko"
] |
Paramiko equvalent of pipline controls and input/output pipes | 2,123,581 | <p>I need a method of paramiko based file transfer with a lightweight <a href="http://en.wikipedia.org/wiki/Secure_Shell#Version_2.0" rel="nofollow">SSH2</a> server (<a href="http://matt.ucc.asn.au/dropbear/dropbear.html" rel="nofollow">dropbear</a>) which has no support for <a href="http://en.wikipedia.org/wiki/Secure... | 5 | 2010-01-23T15:07:07Z | 2,124,522 | <p>pyfilesystem implements an <a href="http://code.google.com/p/pyfilesystem/source/browse/trunk/fs/sftpfs.py" rel="nofollow">sftp filesystem</a> on top of paramiko. </p>
| 1 | 2010-01-23T20:12:04Z | [
"python",
"file",
"transfer",
"paramiko"
] |
Python: multiple properties, one setter/getter | 2,123,585 | <p>Consider the following class definitions</p>
<pre><code>class of2010(object):
def __init__(self):
self._a = 1
self._b = 2
self._c = 3
def set_a(self,value):
print('setting a...')
self._a = value
def set_b(self,value):
print('setting b...')
self._b... | 11 | 2010-01-23T15:08:34Z | 2,123,601 | <p>May be you're looking for
<code>__setattr__(self, name, value)</code></p>
<p>Take a look <a href="http://docs.python.org/reference/datamodel.html#customizing-attribute-access" rel="nofollow">here</a></p>
| 1 | 2010-01-23T15:12:26Z | [
"python",
"properties",
"setter",
"getter-setter"
] |
Python: multiple properties, one setter/getter | 2,123,585 | <p>Consider the following class definitions</p>
<pre><code>class of2010(object):
def __init__(self):
self._a = 1
self._b = 2
self._c = 3
def set_a(self,value):
print('setting a...')
self._a = value
def set_b(self,value):
print('setting b...')
self._b... | 11 | 2010-01-23T15:08:34Z | 2,123,602 | <pre><code>def attrsetter(attr):
def set_any(self, value):
setattr(self, attr, value)
return set_any
a = property(fset=attrsetter('_a'))
b = property(fset=attrsetter('_b'))
c = property(fset=attrsetter('_c'))
</code></pre>
| 19 | 2010-01-23T15:14:16Z | [
"python",
"properties",
"setter",
"getter-setter"
] |
Python: multiple properties, one setter/getter | 2,123,585 | <p>Consider the following class definitions</p>
<pre><code>class of2010(object):
def __init__(self):
self._a = 1
self._b = 2
self._c = 3
def set_a(self,value):
print('setting a...')
self._a = value
def set_b(self,value):
print('setting b...')
self._b... | 11 | 2010-01-23T15:08:34Z | 2,123,616 | <pre><code>class...
def __setattr__(self, name, value):
print 'setting', name
self.__dict__[name] = value
</code></pre>
<p>That's it.</p>
| 2 | 2010-01-23T15:20:23Z | [
"python",
"properties",
"setter",
"getter-setter"
] |
Python: multiple properties, one setter/getter | 2,123,585 | <p>Consider the following class definitions</p>
<pre><code>class of2010(object):
def __init__(self):
self._a = 1
self._b = 2
self._c = 3
def set_a(self,value):
print('setting a...')
self._a = value
def set_b(self,value):
print('setting b...')
self._b... | 11 | 2010-01-23T15:08:34Z | 2,123,730 | <p>I see that your setters just log a message and then simply assign the value - in fact, your accepted answer <em>just</em> assigns the value. Are you using this pattern because it is the Accepted Practice / Conventional Wisdom in some other language, perhaps one whose name starts with "J"? If so, then please learn ... | 5 | 2010-01-23T16:00:52Z | [
"python",
"properties",
"setter",
"getter-setter"
] |
Streaming multiple tweets - from multiple users? - Twitter API | 2,123,651 | <p>I have a big list of <strong>Twitter users</strong> stored in a database, <strong>almost 1000</strong>.</p>
<p>I would like to use the <strong>Streaming API</strong> in order to <strong>stream tweets from these users</strong>, but I cannot find an appropriate way to do this.</p>
<p>Help would be very much apprecia... | 6 | 2010-01-23T15:34:14Z | 2,123,710 | <p>According to the <a href="http://apiwiki.twitter.com/Streaming-API-Documentation#statuses/filter">Twitter API documentation</a>, you can only use the streaming API to follow up to 400 users. For more than that, you'll have to <a href="http://apiwiki.twitter.com/Streaming-API-Documentation#AccessandRateLimiting">requ... | 5 | 2010-01-23T15:54:53Z | [
"php",
"python",
"twitter"
] |
Streaming multiple tweets - from multiple users? - Twitter API | 2,123,651 | <p>I have a big list of <strong>Twitter users</strong> stored in a database, <strong>almost 1000</strong>.</p>
<p>I would like to use the <strong>Streaming API</strong> in order to <strong>stream tweets from these users</strong>, but I cannot find an appropriate way to do this.</p>
<p>Help would be very much apprecia... | 6 | 2010-01-23T15:34:14Z | 8,286,513 | <p>You can track 400 filter words and 5000 userids via streaming api.
Filter words can be something apple, orange, ipad etc...
And in order to track any user's timeline you need to get the user's twitter user id.</p>
| 2 | 2011-11-27T15:09:49Z | [
"php",
"python",
"twitter"
] |
Google App Engine and Django templates: why do these two cases differ? | 2,123,695 | <p>I'm new to Python, and I'm using Google App Engine to build a simple blog to help me learn it. I have the following test code:</p>
<pre><code>entries = db.Query(Entry).order("-published").get()
comments = db.Query(Comment).order("published").get()
self.response.out.write(template.render(templatePath... | 1 | 2010-01-23T15:50:31Z | 2,123,856 | <p>You want to use .fetch(), not get():</p>
<pre><code>entries = db.Query(Entry).order("-published").fetch()
comments = db.Query(Comment).order("published").fetch()
</code></pre>
<p>get() returns only the first item that matches the query criteria, so instead of an iterable collection, you'll get one instance, and En... | 2 | 2010-01-23T16:44:52Z | [
"python",
"google-app-engine",
"django-templates"
] |
Error setting up Mercurial on Windows Server 2008 | 2,123,798 | <p>I want to set up a Mercurial SC server and have been following the instructions found here: http//stackoverflow.com/questions/818571/how-to-setup-mercurial-and-hgwebdir-on-iis</p>
<p>I have checked all my settings multiple times and cannot seem to get passed this error after completing the configuration. <em>Any a... | 5 | 2010-01-23T16:24:53Z | 2,129,114 | <p>The traceback in the very long line says that mercurial isn't found in your PYTHON_PATH. Try making the hgwebdir.cgi edit as seen in step 5.1 from the <a href="http://mercurial.selenic.com/wiki/HgWebDirStepByStep#Mercurial_Lib_Files">HgWebDirStopByStep</a> page.</p>
<pre><code># adjust python path if not a system-... | 6 | 2010-01-24T22:15:54Z | [
"python",
"mercurial",
"windows-server-2008"
] |
when does Python allocate new memory for identical strings? | 2,123,925 | <p>Two Python strings with the same characters, a == b,
may share memory, id(a) == id(b),
or may be in memory twice, id(a) != id(b).
Try</p>
<pre><code>ab = "ab"
print id( ab ), id( "a"+"b" )
</code></pre>
<p>Here Python recognizes that the newly created "a"+"b" is the same
as the "ab" already in memory -- not bad.</... | 26 | 2010-01-23T17:08:14Z | 2,123,934 | <p>I strongly suspect that Python is behaving like many other languages here - recognising string constants <em>within your source code</em> and using a common table for those, but <em>not</em> applying the same rules when creating strings dynamically. This makes sense as there will only be a finite set of strings with... | 14 | 2010-01-23T17:12:02Z | [
"python",
"memory",
"memory-management"
] |
when does Python allocate new memory for identical strings? | 2,123,925 | <p>Two Python strings with the same characters, a == b,
may share memory, id(a) == id(b),
or may be in memory twice, id(a) != id(b).
Try</p>
<pre><code>ab = "ab"
print id( ab ), id( "a"+"b" )
</code></pre>
<p>Here Python recognizes that the newly created "a"+"b" is the same
as the "ab" already in memory -- not bad.</... | 26 | 2010-01-23T17:08:14Z | 2,124,011 | <p>Each <em>implementation</em> of the Python language is free to make its own tradeoffs in allocating immutable objects (such as strings) -- either making a new one, or finding an existing equal one and using one more reference to it, are just fine from the language's point of view. In practice, of course, real-world ... | 33 | 2010-01-23T17:34:30Z | [
"python",
"memory",
"memory-management"
] |
when does Python allocate new memory for identical strings? | 2,123,925 | <p>Two Python strings with the same characters, a == b,
may share memory, id(a) == id(b),
or may be in memory twice, id(a) != id(b).
Try</p>
<pre><code>ab = "ab"
print id( ab ), id( "a"+"b" )
</code></pre>
<p>Here Python recognizes that the newly created "a"+"b" is the same
as the "ab" already in memory -- not bad.</... | 26 | 2010-01-23T17:08:14Z | 2,124,074 | <pre><code>x = 42
y = 42
x == y #True
x is y #True
</code></pre>
<blockquote>
<p>In this interaction, X and Y should be
== (same value), but not is (same object) because we ran two different
literal expressions. Because <strong>small
integers and strings are cached and
reused</strong>, though, is tells us th... | 2 | 2010-01-23T17:54:55Z | [
"python",
"memory",
"memory-management"
] |
when does Python allocate new memory for identical strings? | 2,123,925 | <p>Two Python strings with the same characters, a == b,
may share memory, id(a) == id(b),
or may be in memory twice, id(a) != id(b).
Try</p>
<pre><code>ab = "ab"
print id( ab ), id( "a"+"b" )
</code></pre>
<p>Here Python recognizes that the newly created "a"+"b" is the same
as the "ab" already in memory -- not bad.</... | 26 | 2010-01-23T17:08:14Z | 2,125,618 | <p>A side note: it is very important to know the lifetime of objects in Python. Note the following session:</p>
<pre><code>Python 2.6.4 (r264:75706, Dec 26 2009, 01:03:10)
[GCC 4.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a="a"
>>> b="b"
>>> pr... | 8 | 2010-01-24T02:09:13Z | [
"python",
"memory",
"memory-management"
] |
what is wrong with my ripemd160 python code? | 2,124,165 | <p>everything i have tried has given me wrong output values. i even copied C codes and changed them so that they would work in python and i still get wrong outputs. what is wrong?</p>
<pre><code>import os, math
def makehex(value,size=8):
value = hex(value)[2:]
if value[-1] == 'L':
value = value[0:-1]
... | 1 | 2010-01-23T18:22:16Z | 2,124,289 | <pre><code>>>> import hashlib
>>> data = ''
>>> hashlib.new('ripemd160', data).hexdigest()
'9c1185a5c5e9fc54612808977ee8f548b2258d31'
</code></pre>
| 7 | 2010-01-23T18:56:54Z | [
"python",
"cryptography",
"ripemd"
] |
How do I implement interfaces in python? | 2,124,190 | <pre><code>public interface IInterface
{
void show();
}
public class MyClass : IInterface
{
#region IInterface Members
public void show()
{
Console.WriteLine("Hello World!");
}
#endregion
}
</code></pre>
<p>How do I implement Python equivalent of this C# code ?</p>
<pre><code>clas... | 17 | 2010-01-23T18:29:07Z | 2,124,211 | <p>There are third-party implementations of interfaces for Python (most popular is <a href="http://www.zope.org/Products/ZopeInterface">Zope's</a>, also used in <a href="http://twistedmatrix.com/documents/current/core/howto/plugin.html">Twisted</a>), but more commonly Python coders prefer to use the richer concept know... | 13 | 2010-01-23T18:33:56Z | [
"c#",
"python",
"oop"
] |
How do I implement interfaces in python? | 2,124,190 | <pre><code>public interface IInterface
{
void show();
}
public class MyClass : IInterface
{
#region IInterface Members
public void show()
{
Console.WriteLine("Hello World!");
}
#endregion
}
</code></pre>
<p>How do I implement Python equivalent of this C# code ?</p>
<pre><code>clas... | 17 | 2010-01-23T18:29:07Z | 2,124,220 | <p>Something like this (might not work as I don't have Python around):</p>
<pre><code>class IInterface:
def show(self): raise NotImplementedError
class MyClass(IInterface):
def show(self): print "Hello World!"
</code></pre>
| 9 | 2010-01-23T18:36:23Z | [
"c#",
"python",
"oop"
] |
How do I implement interfaces in python? | 2,124,190 | <pre><code>public interface IInterface
{
void show();
}
public class MyClass : IInterface
{
#region IInterface Members
public void show()
{
Console.WriteLine("Hello World!");
}
#endregion
}
</code></pre>
<p>How do I implement Python equivalent of this C# code ?</p>
<pre><code>clas... | 17 | 2010-01-23T18:29:07Z | 2,124,378 | <p>My understanding is that interfaces are not that necessary in dynamic languages like Python. In Java (or C++ with its abstract base class) interfaces are means for ensuring that e.g. you're passing the right parameter, able to perform set of tasks. </p>
<p>E.g. if you have observer and observable, observable is int... | 3 | 2010-01-23T19:19:41Z | [
"c#",
"python",
"oop"
] |
How do I implement interfaces in python? | 2,124,190 | <pre><code>public interface IInterface
{
void show();
}
public class MyClass : IInterface
{
#region IInterface Members
public void show()
{
Console.WriteLine("Hello World!");
}
#endregion
}
</code></pre>
<p>How do I implement Python equivalent of this C# code ?</p>
<pre><code>clas... | 17 | 2010-01-23T18:29:07Z | 2,124,415 | <p>As mentioned by other here:</p>
<p>Interfaces is not necessary in Python. This is because Python has proper multiple inheritance, and also ducktyping, which means that the places where you <em>must</em> have interfaces in Java, you don't have to have them in Python.</p>
<p>That said, there is still several uses of... | 26 | 2010-01-23T19:35:30Z | [
"c#",
"python",
"oop"
] |
How do I implement interfaces in python? | 2,124,190 | <pre><code>public interface IInterface
{
void show();
}
public class MyClass : IInterface
{
#region IInterface Members
public void show()
{
Console.WriteLine("Hello World!");
}
#endregion
}
</code></pre>
<p>How do I implement Python equivalent of this C# code ?</p>
<pre><code>clas... | 17 | 2010-01-23T18:29:07Z | 23,134,110 | <p>Using the abc module for abstract base classes seems to do the trick.</p>
<pre><code>from abc import ABCMeta, abstractmethod
class IInterface:
__metaclass__ = ABCMeta
@classmethod
def version(self): return "1.0"
@abstractmethod
def show(self): raise NotImplementedError
class MyServer(IInterfa... | 13 | 2014-04-17T13:11:36Z | [
"c#",
"python",
"oop"
] |
Reassembling Python bytecode to the original code? | 2,124,202 | <p>This might be a silly question, but, given the output of, say..</p>
<pre><code>>>> from dis import dis
>>> def myfunc(x):
... print x ** 2
...
>>> dis(myfunc)
2 0 LOAD_FAST 0 (x)
3 LOAD_CONST 1 (2)
6 BINARY_POWER ... | 7 | 2010-01-23T18:32:20Z | 2,125,396 | <p><a href="http://sourceforge.net/projects/decompyle/">http://sourceforge.net/projects/decompyle/</a></p>
| 5 | 2010-01-24T00:44:21Z | [
"python",
"bytecode",
"bytecode-manipulation"
] |
Reading corrupted file in python | 2,124,238 | <p>I've got a file, that looks like this <img src="http://img40.imageshack.us/img40/4581/crapq.png" alt="alt text">
Now there are 5 lines shown. However running this script</p>
<pre><code>with open('hello.txt', 'r') as hello:
for line in hello:
print line,
</code></pre>
<p>gives</p>
<pre><code>num 1
ctl0... | 1 | 2010-01-23T18:40:57Z | 2,124,269 | <pre><code>entire_file = open('hello.txt', 'rb').read()
print 'number of \\n: %d, number of bytes %d' % (
entire_file.count('\n'), len(entire_file))
</code></pre>
| 6 | 2010-01-23T18:49:30Z | [
"python"
] |
PyGTK, how can I lock a window so it cannot be resized? | 2,124,296 | <p>I am looking for a way to lock the window. I found <code>window.set_resizable(False)</code>, but that resizes the window to its requested size and <em>then</em> locks it. I would like to be able to resize my window, and then lock it into the size I have resized it to.</p>
| 0 | 2010-01-23T18:58:19Z | 2,124,325 | <p>Perhaps you could <code>set_size_request</code> with the current window size (from <code>window_get_size</code>) before you call <code>set_resizeable</code>?</p>
| 3 | 2010-01-23T19:06:59Z | [
"python",
"gtk",
"window",
"pygtk",
"resizable"
] |
PyGTK, how can I lock a window so it cannot be resized? | 2,124,296 | <p>I am looking for a way to lock the window. I found <code>window.set_resizable(False)</code>, but that resizes the window to its requested size and <em>then</em> locks it. I would like to be able to resize my window, and then lock it into the size I have resized it to.</p>
| 0 | 2010-01-23T18:58:19Z | 15,961,711 | <p>You can use this:</p>
<p>window.set_geometry_hints(window, min_width, min_height, max_width, max_height)</p>
| 0 | 2013-04-12T01:38:27Z | [
"python",
"gtk",
"window",
"pygtk",
"resizable"
] |
Having "Exception Value: The _imaging C module is not installed" with my Buildout/Python/Django/PIL on Mac OSX SL? | 2,124,306 | <p>I'm using Buildout for my Django projects, with FeinCMS. I've got it setup great locally on my Mac OSX Snow Leopard, with no errors coming up at all when I use runserver. But when I upload an image with FeinCMS in the admin area it comes up with a
"Exception Value: The _imaging C module is not installed" error.</p>... | 2 | 2010-01-23T19:00:51Z | 2,235,110 | <p>I have gone through the same thing today and found a solution. The problem is that PIL will look for 32-bit libjpeg and Snow Leopard will compile the library as x86_64 by default. This could be fixed by modifying your libjpeg section to look like this:</p>
<pre><code>[libjpeg]
recipe = hexagonit.recipe.cmmi
url = h... | 2 | 2010-02-10T07:27:23Z | [
"python",
"django",
"python-imaging-library",
"buildout"
] |
how to generate permutations of array in python? | 2,124,347 | <p>i have an array of 27 elements,and i don't want to generate all permutations of array (27!)
i need 5000 randomly choosed permutations,any tip will be useful...</p>
| 20 | 2010-01-23T19:12:57Z | 2,124,353 | <p><a href="http://docs.python.org/library/itertools.html#itertools.permutations"><code>itertools.permutations</code></a>. It's a generator, so it won't create the whole list of permutations. You could skip randomly until you've got 5000.</p>
| 5 | 2010-01-23T19:14:14Z | [
"python",
"permutation"
] |
how to generate permutations of array in python? | 2,124,347 | <p>i have an array of 27 elements,and i don't want to generate all permutations of array (27!)
i need 5000 randomly choosed permutations,any tip will be useful...</p>
| 20 | 2010-01-23T19:12:57Z | 2,124,356 | <p>You may want the itertools.permutations() function. Gotta love that itertools module!</p>
<p>NOTE: New in 2.6</p>
| 1 | 2010-01-23T19:14:54Z | [
"python",
"permutation"
] |
how to generate permutations of array in python? | 2,124,347 | <p>i have an array of 27 elements,and i don't want to generate all permutations of array (27!)
i need 5000 randomly choosed permutations,any tip will be useful...</p>
| 20 | 2010-01-23T19:12:57Z | 2,124,365 | <pre><code>import random
perm_list = []
for i in range(5000):
temp = range(27)
random.shuffle(temp)
perm_list.append(temp)
print(perm_list)
</code></pre>
<p><code>10888869450418352160768000000</code> I love big numbers! :)</p>
<p>AND</p>
<p><strong><code>10888869450418352160768000001</code> is PRIME!... | 9 | 2010-01-23T19:16:25Z | [
"python",
"permutation"
] |
how to generate permutations of array in python? | 2,124,347 | <p>i have an array of 27 elements,and i don't want to generate all permutations of array (27!)
i need 5000 randomly choosed permutations,any tip will be useful...</p>
| 20 | 2010-01-23T19:12:57Z | 2,124,370 | <p>To generate one permutation use <a href="http://docs.python.org/library/random.html#random.shuffle"><code>random.shuffle</code></a> and store a copy of the result. Repeat this operation in a loop and each time check for duplicates (there probably won't be any though). Once you have 5000 items in your result set, sto... | 30 | 2010-01-23T19:17:12Z | [
"python",
"permutation"
] |
how to generate permutations of array in python? | 2,124,347 | <p>i have an array of 27 elements,and i don't want to generate all permutations of array (27!)
i need 5000 randomly choosed permutations,any tip will be useful...</p>
| 20 | 2010-01-23T19:12:57Z | 3,241,894 | <pre><code># apermindex should be a number between 0 and factorial(len(alist))
def perm_given_index(alist, apermindex):
for i in range(len(alist)-1):
apermindex, j = divmod(apermindex, len(alist)-i)
alist[i], alist[i+j] = alist[i+j], alist[i]
return alist
</code></pre>
<p>Usage: <code>perm_give... | 2 | 2010-07-13T21:59:20Z | [
"python",
"permutation"
] |
Enabling overriding of app template in django? | 2,124,399 | <p>I'm writing a simple site to display statistics for some data, and I've got an app called "stats", that I'd like to write default templates for (places in stats/templates/stats), but I'd like these to be overridable in the same way that the templates for the admin app are. IE: If I put a stats/view.html in my proje... | 1 | 2010-01-23T19:27:46Z | 2,124,466 | <p>You need to put <code>filesystem</code> loader <strong>before</strong> <code>app_directories</code> loader in your <code>TEMPLATE_LOADERS</code> setting.</p>
<pre><code>TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_sour... | 2 | 2010-01-23T19:50:50Z | [
"python",
"django",
"templates"
] |
Python / Linux/ Daemon process trying to show gtk.messagedialog | 2,124,455 | <p>on Ubuntu 8/9,
i'm trying to write a daemon in python, that monitors a certain network condition and informs the user using a gtk.messagedialog.
I installed this script using rc-update.
The daemon starts at boot, but doesn't show the dialog even after I login. I assume because init.d starts my daemon at tty1 and no... | 0 | 2010-01-23T19:48:25Z | 2,124,510 | <p>In order to find out whether your code works at all, you should first try and execute the daemon as normal program in a graphical shell (on a GNOME desktop).</p>
<p>You could also call <a href="http://library.gnome.org/users/zenity/2.28/zenity.html" rel="nofollow">zenity</a>.</p>
| 0 | 2010-01-23T20:05:19Z | [
"python",
"linux",
"ubuntu",
"gtk",
"daemon"
] |
Python / Linux/ Daemon process trying to show gtk.messagedialog | 2,124,455 | <p>on Ubuntu 8/9,
i'm trying to write a daemon in python, that monitors a certain network condition and informs the user using a gtk.messagedialog.
I installed this script using rc-update.
The daemon starts at boot, but doesn't show the dialog even after I login. I assume because init.d starts my daemon at tty1 and no... | 0 | 2010-01-23T19:48:25Z | 2,124,579 | <p>If five users are logged in to X sessions, who gets the message? Everyone?</p>
<p>If someone is logged in locally but only using the tty, and not X11, should they see the message?</p>
<p>If someone is logged in remotely via ssh -X to run a graphic application on their own system off of your CPU, should they see th... | 3 | 2010-01-23T20:28:32Z | [
"python",
"linux",
"ubuntu",
"gtk",
"daemon"
] |
Python / Linux/ Daemon process trying to show gtk.messagedialog | 2,124,455 | <p>on Ubuntu 8/9,
i'm trying to write a daemon in python, that monitors a certain network condition and informs the user using a gtk.messagedialog.
I installed this script using rc-update.
The daemon starts at boot, but doesn't show the dialog even after I login. I assume because init.d starts my daemon at tty1 and no... | 0 | 2010-01-23T19:48:25Z | 2,136,615 | <p>You may use <code>notify-send</code> (from <code>libnotify-bin</code> package) to send notifications to desktop users from your daemon.</p>
| 0 | 2010-01-25T23:54:12Z | [
"python",
"linux",
"ubuntu",
"gtk",
"daemon"
] |
How does Timer in Python work, regarding mutlithreading? | 2,124,540 | <p>If I call </p>
<pre><code>Timer(.1, some_function, [some_arguments]).start()
</code></pre>
<p>multiple times, what exactly happens behind the scenes?</p>
<p>The source of our problem is ...</p>
<p>We have a method that's essentially:</p>
<pre><code>def move(target):
force = calculateForce(target-getCurrentPosi... | 1 | 2010-01-23T20:19:37Z | 2,124,577 | <p>Right: each call to <code>Timer</code> does start a new thread. Indeed, class <code>threading.Timer</code> is <em>documented</em> as being "a thread". You can confirm this by reading <a href="http://svn.python.org/view/python/trunk/Lib/threading.py?annotate=76172" rel="nofollow">the source code</a>, line 707.</p>
... | 3 | 2010-01-23T20:28:10Z | [
"python",
"multithreading"
] |
pyinstaller: 2 instances of my cherrypy app exe get executed | 2,124,603 | <p>I have a cherrypy app that I've made an exe with pyinstaller.
now when I run the exe it loads itself twice into memory. Watching the taskmanager shows the first instance load into about 1k, then a second later a second instance of hte exe loads into about 3k ram. If I close the bigger one both processes die. If I c... | 6 | 2010-01-23T20:34:54Z | 2,130,453 | <p>It would be important to know what version of CherryPy you are using. The 2.x line had an unfortunate design: the autoreloader feature always started a second instance of CherryPy, so the first could respawn the child when it was killed off. That was fixed in version 3 to only use one process. If you are using versi... | 1 | 2010-01-25T05:52:26Z | [
"python",
"cherrypy",
"pyinstaller"
] |
pyinstaller: 2 instances of my cherrypy app exe get executed | 2,124,603 | <p>I have a cherrypy app that I've made an exe with pyinstaller.
now when I run the exe it loads itself twice into memory. Watching the taskmanager shows the first instance load into about 1k, then a second later a second instance of hte exe loads into about 3k ram. If I close the bigger one both processes die. If I c... | 6 | 2010-01-23T20:34:54Z | 2,641,796 | <p>PyInstaller spawns a subprocess during its boot process. This is explained in <a href="http://www.pyinstaller.org/export/latest/tags/1.4/doc/Manual.html?format=raw#how-one-file-mode-works" rel="nofollow">a section of its manual</a>.</p>
| 3 | 2010-04-14T23:40:50Z | [
"python",
"cherrypy",
"pyinstaller"
] |
Pretty printing a list of list of floats? | 2,124,645 | <p>Basically i have to dump a series of temperature readings, into a text file. This is a space delimited list of elements, where each row represents something (i don't know, and it just gets forced into a fortran model, <em>shudder</em>). I am more or less handling it from our groups side, which is extracting those te... | 3 | 2010-01-23T20:45:50Z | 2,124,693 | <p>you can right-pad like this:</p>
<pre><code>str = '%-10f' % val
</code></pre>
<p>to left pad:</p>
<pre><code>set = '%10f' % val
</code></pre>
<p>or in combination pad and set the precision to 4 decimal places:</p>
<pre><code>str = '%-10.4f' % val
</code></pre>
<p>:</p>
<pre><code>import sys
rows = [[1.343, 34... | 3 | 2010-01-23T20:56:35Z | [
"python"
] |
Pretty printing a list of list of floats? | 2,124,645 | <p>Basically i have to dump a series of temperature readings, into a text file. This is a space delimited list of elements, where each row represents something (i don't know, and it just gets forced into a fortran model, <em>shudder</em>). I am more or less handling it from our groups side, which is extracting those te... | 3 | 2010-01-23T20:45:50Z | 2,124,711 | <p>If you also want to display a fixed number of decimals (which probably makes sense if the numbers are really temperature readings), something like this gives quite nice output:</p>
<pre><code>for line in temperature_readings:
for value in line:
print '%10.2f' % value,
print
</code></pre>
<p>Output:</p>... | 1 | 2010-01-23T21:01:43Z | [
"python"
] |
Pretty printing a list of list of floats? | 2,124,645 | <p>Basically i have to dump a series of temperature readings, into a text file. This is a space delimited list of elements, where each row represents something (i don't know, and it just gets forced into a fortran model, <em>shudder</em>). I am more or less handling it from our groups side, which is extracting those te... | 3 | 2010-01-23T20:45:50Z | 2,124,712 | <p>Check out <a href="http://docs.python.org/library/pprint.html" rel="nofollow">Python pprint</a>. </p>
<blockquote>
<p>The pprint module provides a capability to âpretty-printâ arbitrary Python data structures in a form which can be used as input to the interpreter.</p>
<p>[...]</p>
<p>This example d... | -1 | 2010-01-23T21:02:02Z | [
"python"
] |
Pretty printing a list of list of floats? | 2,124,645 | <p>Basically i have to dump a series of temperature readings, into a text file. This is a space delimited list of elements, where each row represents something (i don't know, and it just gets forced into a fortran model, <em>shudder</em>). I am more or less handling it from our groups side, which is extracting those te... | 3 | 2010-01-23T20:45:50Z | 2,124,726 | <p>In Python 2.*,</p>
<pre><code>for sublist in temperature_readings:
for item in sublist:
print '%15.6f' % item,
print
</code></pre>
<p>emits</p>
<pre><code> 1.343000 348.222000 484844.333300
12349.000002 -2.433330
</code></pre>
<p>for your example. Tweak the lengths and numb... | 1 | 2010-01-23T21:04:56Z | [
"python"
] |
Pretty printing a list of list of floats? | 2,124,645 | <p>Basically i have to dump a series of temperature readings, into a text file. This is a space delimited list of elements, where each row represents something (i don't know, and it just gets forced into a fortran model, <em>shudder</em>). I am more or less handling it from our groups side, which is extracting those te... | 3 | 2010-01-23T20:45:50Z | 2,124,747 | <p>The % (String formatting) operator is deprecated now.</p>
<p>You can use str.format to do pretty printing in Python.</p>
<p>Something like this might work for you:</p>
<pre><code>for set in temperature_readings:
for temp in set:
print "{0:10.4f}\t".format(temp),
print
</code></pre>
<p>Which print... | 2 | 2010-01-23T21:11:21Z | [
"python"
] |
(Py)GTK StatusIcon notifications on Windows | 2,124,683 | <p>I'm currently writing a screen capture app for Windows and Linux using PyGTK, and I've hit a slight problem with displaying notifications. On Linux, I've been using the libnotify bindings to provide notifications, which has been working very well; however, this has no equivalent on Windows.</p>
<p>I'd <a href="http... | 1 | 2010-01-23T20:54:02Z | 2,125,089 | <p>Looking at the <a href="http://git.gnome.org/browse/gtk+/tree/gtk/gtkstatusicon.c" rel="nofollow">GtkStatusIcon source code</a> I don't see the NOTIFYICONDATA exposed anywhere. For X11 there is <a href="http://library.gnome.org/devel/gtk/unstable/GtkStatusIcon.html#gtk-status-icon-get-x11-window-id" rel="nofollow">g... | 2 | 2010-01-23T23:04:28Z | [
"python",
"winapi",
"gtk",
"pygtk",
"notifications"
] |
iPhone app with Google App Engine | 2,124,688 | <p>I've prototyped an iPhone app that uses (internally) SQLite as its data base. The intent was to ultimately have it communicate with a server via PHP, which would use MySQL as the back-end database. </p>
<p>I just discovered Google App Engine, however, but know very little about it. I think it'd be nice to use th... | 2 | 2010-01-23T20:55:34Z | 2,124,702 | <p>I think this <a href="http://www.ibm.com/developerworks/web/library/wa-aj-iphone/" rel="nofollow">article</a> should help you.</p>
<blockquote>
<p><strong>Summary:</strong> Cloud computing and software development for handheld devices are two very hot technologies that are increasingly being combined to create h... | 1 | 2010-01-23T20:58:23Z | [
"iphone",
"python",
"google-app-engine",
"gql"
] |
iPhone app with Google App Engine | 2,124,688 | <p>I've prototyped an iPhone app that uses (internally) SQLite as its data base. The intent was to ultimately have it communicate with a server via PHP, which would use MySQL as the back-end database. </p>
<p>I just discovered Google App Engine, however, but know very little about it. I think it'd be nice to use th... | 2 | 2010-01-23T20:55:34Z | 2,124,705 | <p>That's a pretty generic question :)</p>
<p>Short answer: yes. It's going to involve some rethinking of your data model, but yes, changes are you can support it with the GAE Datastore API.</p>
<p>When you create your Python models (think of these as tables), you can certainly define references to other models (so ... | 1 | 2010-01-23T20:59:41Z | [
"iphone",
"python",
"google-app-engine",
"gql"
] |
iPhone app with Google App Engine | 2,124,688 | <p>I've prototyped an iPhone app that uses (internally) SQLite as its data base. The intent was to ultimately have it communicate with a server via PHP, which would use MySQL as the back-end database. </p>
<p>I just discovered Google App Engine, however, but know very little about it. I think it'd be nice to use th... | 2 | 2010-01-23T20:55:34Z | 2,124,718 | <p>True, Google App Engine is a very cool product, but the datastore is a different beast than a regular mySQL database. That's not to say that what you need can't be done with the GAE datastore; however it may take some reworking on your end. </p>
<p>The most prominent different that you notice right off the start i... | 2 | 2010-01-23T21:03:25Z | [
"iphone",
"python",
"google-app-engine",
"gql"
] |
iPhone app with Google App Engine | 2,124,688 | <p>I've prototyped an iPhone app that uses (internally) SQLite as its data base. The intent was to ultimately have it communicate with a server via PHP, which would use MySQL as the back-end database. </p>
<p>I just discovered Google App Engine, however, but know very little about it. I think it'd be nice to use th... | 2 | 2010-01-23T20:55:34Z | 2,125,297 | <p>GQL offers almost no functionality at all; it's only used for SELECT queries, and it only exists to make writing SELECT queries easier for SQL programmers. Behind the scenes, it converts your queries to db.Query objects.</p>
<p>The App Engine datastore isn't a relational database at all. You can do some stuff tha... | 2 | 2010-01-23T23:59:37Z | [
"iphone",
"python",
"google-app-engine",
"gql"
] |
Why am I getting dups with random.shuffle in Python? | 2,124,748 | <p>For a list of 10 ints, there are 10! possible orders or permutations. Why does random.shuffle give duplicates after only 5000 tries?</p>
<pre><code>>>> L = range(10)
>>> rL = list()
>>> for i in range(5000):
... random.shuffle(L)
... rL.append(L[:])
...
>>> rL = [tuple(... | 4 | 2010-01-23T21:11:22Z | 2,124,762 | <p>Because it's... random! If you want all permutations just use itertools.permutations.</p>
| 6 | 2010-01-23T21:15:35Z | [
"python",
"random",
"probability",
"birthday-paradox"
] |
Why am I getting dups with random.shuffle in Python? | 2,124,748 | <p>For a list of 10 ints, there are 10! possible orders or permutations. Why does random.shuffle give duplicates after only 5000 tries?</p>
<pre><code>>>> L = range(10)
>>> rL = list()
>>> for i in range(5000):
... random.shuffle(L)
... rL.append(L[:])
...
>>> rL = [tuple(... | 4 | 2010-01-23T21:11:22Z | 2,124,777 | <p>maybe because is RANDOM? Random does not mean does not repeat, it means it is RANDOM, which means theoretically it could return the exact same answer every time, not likely but possible.</p>
| 2 | 2010-01-23T21:18:38Z | [
"python",
"random",
"probability",
"birthday-paradox"
] |
Why am I getting dups with random.shuffle in Python? | 2,124,748 | <p>For a list of 10 ints, there are 10! possible orders or permutations. Why does random.shuffle give duplicates after only 5000 tries?</p>
<pre><code>>>> L = range(10)
>>> rL = list()
>>> for i in range(5000):
... random.shuffle(L)
... rL.append(L[:])
...
>>> rL = [tuple(... | 4 | 2010-01-23T21:11:22Z | 2,124,788 | <p>It's called the <a href="http://en.wikipedia.org/wiki/Birthday_problem" rel="nofollow">Birthday Paradox</a>.</p>
<p>According to this formula from Wikipedia:</p>
<p><img src="http://upload.wikimedia.org/math/4/b/c/4bc824acea44ca061aaf9ef3ea0e9d9b.png"></p>
<p>but replacing <code>365</code> with <code>10!</code> y... | 19 | 2010-01-23T21:22:06Z | [
"python",
"random",
"probability",
"birthday-paradox"
] |
How to return the count of related entities in sqlalchemy query | 2,125,041 | <p>I'm new to sqlalchemy, and while the documentation seems fairly thorough, I couldn't find a way to do quite what I want.</p>
<p>Say I have two tables: forum and post. Each forum has a parent forum, and any number of posts. What I want is:</p>
<ul>
<li>A list of top-level forums</li>
<li>Eagerly loaded child forums... | 9 | 2010-01-23T22:50:03Z | 2,132,503 | <p>Because you want the post count to be accessible on the child Forum objects you'll need to declare it as a column property when setting up the mappers. The column property declaration should look something like this (assuming you use declarative):</p>
<pre><code>Forum.post_count = column_property(select([func.count... | 8 | 2010-01-25T13:21:34Z | [
"python",
"sql",
"sqlalchemy"
] |
Unit Conversion in Python | 2,125,076 | <p>I'm working on a project that lets users track different data types over time. Part of the base idea is that a user should be able to enter data using any units that they need to. I've been looking at both units:</p>
<p><a href="http://pypi.python.org/pypi/units/">http://pypi.python.org/pypi/units/</a></p>
<p>and ... | 35 | 2010-01-23T23:02:21Z | 2,127,511 | <p>I think you should use quantities, because a quantity has some units associated with it.</p>
<p>Pressure, for example, will be a quantity that could be entered and converted in and to different units (Pa, psi, atm, etc). Probably you could create new quantities specifics for your application.</p>
| 1 | 2010-01-24T15:20:56Z | [
"python",
"units-of-measurement"
] |
Unit Conversion in Python | 2,125,076 | <p>I'm working on a project that lets users track different data types over time. Part of the base idea is that a user should be able to enter data using any units that they need to. I've been looking at both units:</p>
<p><a href="http://pypi.python.org/pypi/units/">http://pypi.python.org/pypi/units/</a></p>
<p>and ... | 35 | 2010-01-23T23:02:21Z | 2,209,188 | <p>I applaud use of explicit units in scientific computing applications. Using explicit units is analogous brushing your teeth. It adds some tedium up front, but the type safety you get can save a lot of trouble in the long run. Like, say, <a href="http://www.cnn.com/TECH/space/9909/30/mars.metric.02/">not crashing ... | 23 | 2010-02-05T17:49:50Z | [
"python",
"units-of-measurement"
] |
Unit Conversion in Python | 2,125,076 | <p>I'm working on a project that lets users track different data types over time. Part of the base idea is that a user should be able to enter data using any units that they need to. I've been looking at both units:</p>
<p><a href="http://pypi.python.org/pypi/units/">http://pypi.python.org/pypi/units/</a></p>
<p>and ... | 35 | 2010-01-23T23:02:21Z | 3,983,202 | <p>It looks like another package has come out for doing this as well, written by Massimo DiPierro of web2py fame, called <a href="https://github.com/mdipierro/buckingham" rel="nofollow">Buckingham</a>.</p>
<p>Also of note, <a href="http://www.briansimulator.org/" rel="nofollow">Brian</a> has had something like this fo... | 4 | 2010-10-20T23:46:43Z | [
"python",
"units-of-measurement"
] |
Unit Conversion in Python | 2,125,076 | <p>I'm working on a project that lets users track different data types over time. Part of the base idea is that a user should be able to enter data using any units that they need to. I've been looking at both units:</p>
<p><a href="http://pypi.python.org/pypi/units/">http://pypi.python.org/pypi/units/</a></p>
<p>and ... | 35 | 2010-01-23T23:02:21Z | 9,274,117 | <p>Note that <code>quantities</code> has very bad support for temperature:</p>
<pre><code>>>> (100 * pq.degC).rescale(pq.degF)
array(179.99999999999997) * degF
>>> (0 * pq.degC).rescale(pq.degF)
array(0.0) * degF
</code></pre>
<p>0 degrees Celsius isn't 0 degrees Fahrenheit. Their framework doesn't ... | 6 | 2012-02-14T09:02:39Z | [
"python",
"units-of-measurement"
] |
Unit Conversion in Python | 2,125,076 | <p>I'm working on a project that lets users track different data types over time. Part of the base idea is that a user should be able to enter data using any units that they need to. I've been looking at both units:</p>
<p><a href="http://pypi.python.org/pypi/units/">http://pypi.python.org/pypi/units/</a></p>
<p>and ... | 35 | 2010-01-23T23:02:21Z | 17,034,705 | <p><a href="https://pint.readthedocs.org/en/latest/">Pint</a> has recently come onto the field. Anybody care to share their experiences? Looks good. FYI: It looks like <a href="http://pythonhosted.org/uncertainties/#future-developments">Pint will be integrated with Uncertainties</a> in the near future.</p>
| 10 | 2013-06-11T00:06:16Z | [
"python",
"units-of-measurement"
] |
Unit Conversion in Python | 2,125,076 | <p>I'm working on a project that lets users track different data types over time. Part of the base idea is that a user should be able to enter data using any units that they need to. I've been looking at both units:</p>
<p><a href="http://pypi.python.org/pypi/units/">http://pypi.python.org/pypi/units/</a></p>
<p>and ... | 35 | 2010-01-23T23:02:21Z | 25,210,593 | <p>You may want to look at a new package called <a href="https://github.com/kdavies4/natu" rel="nofollow">natu</a>. It addresses the three issues that @ChristopherBruns listed. It's available in <a href="https://pypi.python.org/pypi/natu" rel="nofollow">PyPI</a>.</p>
<p>I'm the author of that package, and I'd apprecia... | 2 | 2014-08-08T19:06:07Z | [
"python",
"units-of-measurement"
] |
How can I see error logs of Django views | 2,125,080 | <p>I'm coding a small application with Django. But I can't see any error logs in the console when an error (e.g. Python syntax error, etc.) occurs in one of my views -no action at all.</p>
<p>How can I see the error logs of my views? Debugging like a blind is really annoying.</p>
| 10 | 2010-01-23T23:02:39Z | 2,125,399 | <p>Django does not print any errors to the console by default. Instead it provides very helpful error pages that are displayed for any errors that occur in your views. Please check what your <code>DEBUG</code> setting is set to. In development this should be <code>True</code> which will give you the nice error pages fo... | 5 | 2010-01-24T00:44:59Z | [
"python",
"django",
"logging"
] |
Network IPC With Authentication (in Python) | 2,125,149 | <p>I am looking for a way to connect a frontend server (running Django) with a backend server.
I want to avoid inventing my own protocol on top of a socket, so my plan was to use SimpleHTTPServer + JSON or XML.</p>
<p>However, we also require some security (authentication + encryption) for the connection, which isn't ... | 1 | 2010-01-23T23:18:44Z | 2,125,162 | <p>Use a client side certificate for the connection. This is a good monetization technique to get more income for your client side app.</p>
| 1 | 2010-01-23T23:21:28Z | [
"python",
"json",
"networking",
"ipc"
] |
Python: how so fast? | 2,125,159 | <p>The period of the Mersenne Twister used in the module <code>random</code> is (I am told) 2**19937 - 1. As a binary number, that is 19937 '1's in a row (if I'm not mistaken). Python converts it to decimal pretty darned fast:</p>
<pre><code>$ python -m timeit '2**19937'
10000000 loops, best of 3: 0.0271 usec per lo... | 6 | 2010-01-23T23:21:10Z | 2,125,181 | <p>Hate to rain on your parade, but the reason it's so fast is because the math module is actually not implemented in Python.</p>
<p>Python supports loading shared libraries that export Python APIs, but are implemented in other languages. math.so, which provides the module you get from <code>import math</code>, happen... | 6 | 2010-01-23T23:27:00Z | [
"python",
"largenumber",
"computation"
] |
Python: how so fast? | 2,125,159 | <p>The period of the Mersenne Twister used in the module <code>random</code> is (I am told) 2**19937 - 1. As a binary number, that is 19937 '1's in a row (if I'm not mistaken). Python converts it to decimal pretty darned fast:</p>
<pre><code>$ python -m timeit '2**19937'
10000000 loops, best of 3: 0.0271 usec per lo... | 6 | 2010-01-23T23:21:10Z | 2,125,186 | <p>I know little to nothing about how this is <em>actually</em> implemented in Python, but given that this is basically primitive multiplication and logarithms, I'm not terribly surprised that it's reasonably fast even on quite large numbers.</p>
<p>There are arbitrary precision math libraries such as <a href="http://... | 0 | 2010-01-23T23:28:48Z | [
"python",
"largenumber",
"computation"
] |
Python: how so fast? | 2,125,159 | <p>The period of the Mersenne Twister used in the module <code>random</code> is (I am told) 2**19937 - 1. As a binary number, that is 19937 '1's in a row (if I'm not mistaken). Python converts it to decimal pretty darned fast:</p>
<pre><code>$ python -m timeit '2**19937'
10000000 loops, best of 3: 0.0271 usec per lo... | 6 | 2010-01-23T23:21:10Z | 2,125,259 | <blockquote>
<p>Python converts it to decimal pretty darned fast.</p>
</blockquote>
<p>I don't know Python, but no, it needn't to do that. 2^19937 don't need computations, it is simply a binary shift ("<<") with 19937, so it is very fast. Only if you print that in decimal the actual conversion is necessary and... | 4 | 2010-01-23T23:48:54Z | [
"python",
"largenumber",
"computation"
] |
Python: how so fast? | 2,125,159 | <p>The period of the Mersenne Twister used in the module <code>random</code> is (I am told) 2**19937 - 1. As a binary number, that is 19937 '1's in a row (if I'm not mistaken). Python converts it to decimal pretty darned fast:</p>
<pre><code>$ python -m timeit '2**19937'
10000000 loops, best of 3: 0.0271 usec per lo... | 6 | 2010-01-23T23:21:10Z | 2,125,264 | <p>When compiling to byte code, constant expressions such as <code>2**19937</code> will optimized down to a single constant:</p>
<pre><code>>>> def foo(): return 2**10
...
>>> import dis
>>> dis.dis(foo)
1 0 LOAD_CONST 3 (1024)
3 RETURN_VALUE
... | 5 | 2010-01-23T23:49:35Z | [
"python",
"largenumber",
"computation"
] |
Hudson build failed using Python & Coverage | 2,125,164 | <p>I completed <a href="http://www.rhonabwy.com/wp/2009/11/04/setting-up-a-python-ci-server-with-hudson/comment-page-1/#comment-102826" rel="nofollow">this tutorial</a> from Joe Heck to set up <strong>Hudson</strong> for <strong>Python</strong>. Everything worked perfectly except the <strong>Coverage</strong> section. ... | 3 | 2010-01-23T23:21:55Z | 2,125,549 | <p>You have an old version of coverage.py, it looks like 2.x of some sort. "coverage run" is new syntax with coverage.py 3.x. Download the latest coverage.py at <a href="http://pypi.python.org/pypi/coverage" rel="nofollow">http://pypi.python.org/pypi/coverage</a>, and you should be good to go.</p>
| 4 | 2010-01-24T01:42:12Z | [
"python",
"continuous-integration",
"hudson",
"code-coverage",
"python-coverage"
] |
Python property | 2,125,166 | <p>The output seems a bit fishy given the following code. Why is "get in Base" only printed once? And why is not "set in Base" printed at all? The actual getting/setting seems to work fine though. What am I missing?</p>
<pre><code>class Base:
def __init__(self):
self.s = "BaseStr"
def getstr(self):
... | 8 | 2010-01-23T23:22:07Z | 2,125,180 | <p>You need to use <a href="http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes">new-style classes</a> for properties to work correctly. To do so derive your class from <code>object</code>:</p>
<pre><code>class Base(object):
...
</code></pre>
| 18 | 2010-01-23T23:26:50Z | [
"python",
"properties"
] |
Python property | 2,125,166 | <p>The output seems a bit fishy given the following code. Why is "get in Base" only printed once? And why is not "set in Base" printed at all? The actual getting/setting seems to work fine though. What am I missing?</p>
<pre><code>class Base:
def __init__(self):
self.s = "BaseStr"
def getstr(self):
... | 8 | 2010-01-23T23:22:07Z | 2,126,305 | <p>Whenever creating a new class, derive it from the <code>object</code> type.</p>
| 1 | 2010-01-24T07:31:23Z | [
"python",
"properties"
] |
stopping a cherrypy server over http | 2,125,175 | <p>I have a cherrypy app that I'm controlling over http with a wxpython ui. I want to kill the server when the ui closes, but I don't know how to do that. Right now I'm just doing a sys.exit() on the window close event but thats resulting in </p>
<pre><code>Traceback (most recent call last):
File "ui.py", line 67, i... | 6 | 2010-01-23T23:24:38Z | 2,130,438 | <p>How are you stopping CherryPy? By sending a SIGKILL to itself? You should send TERM instead at the least, but even better would be to call <code>cherrypy.engine.exit()</code> (version 3.1+). Both techniques will allow CherryPy to shut down more gracefully, which includes allowing any in-process requests (like your "... | 7 | 2010-01-25T05:47:14Z | [
"python",
"cherrypy"
] |
stopping a cherrypy server over http | 2,125,175 | <p>I have a cherrypy app that I'm controlling over http with a wxpython ui. I want to kill the server when the ui closes, but I don't know how to do that. Right now I'm just doing a sys.exit() on the window close event but thats resulting in </p>
<pre><code>Traceback (most recent call last):
File "ui.py", line 67, i... | 6 | 2010-01-23T23:24:38Z | 2,498,288 | <p>I use os._exit. I also put it on a thread, so that I can serve up a "you've quit the server" page before exiting.</p>
<pre><code>class MyApp(object):
@cherrypy.expose
def exit(self):
"""
/exit
Quits the application
"""
threading.Timer(1, lambda: os._exit(0)).start()
... | 3 | 2010-03-23T07:47:55Z | [
"python",
"cherrypy"
] |
Python and Rpy2: Calling plot function with options that have "." in them | 2,125,218 | <p>I'm just starting to learn how to use rpy2 with python. I'm able to make simple plots and such, but I've run into the problem that many options in R use ".". For example, here's an R call that works:</p>
<blockquote>
<p>barplot(t, col=heat.colors(2), names.arg=c("pwn", "pwn2"))</p>
</blockquote>
<p>where t is ... | 8 | 2010-01-23T23:36:47Z | 2,125,365 | <p>I don't know whether Rpy will accept this, but you can have keyword parameters with periods in them. You have to pass them through a dictionary though. Like this:</p>
<pre><code>>>> def f(**kwds): print kwds
...
>>> f(a=5, b_c=6)
{'a': 5, 'b_c': 6}
>>> f(a=5, b.c=6)
Traceback ( File "&l... | 1 | 2010-01-24T00:34:02Z | [
"python",
"rpy2"
] |
Python and Rpy2: Calling plot function with options that have "." in them | 2,125,218 | <p>I'm just starting to learn how to use rpy2 with python. I'm able to make simple plots and such, but I've run into the problem that many options in R use ".". For example, here's an R call that works:</p>
<blockquote>
<p>barplot(t, col=heat.colors(2), names.arg=c("pwn", "pwn2"))</p>
</blockquote>
<p>where t is ... | 8 | 2010-01-23T23:36:47Z | 2,125,767 | <p>You can use a dictionary here for the named arguments (<a href="http://docs.python.org/tutorial/controlflow.html#keyword-arguments">using **</a>) as <a href="http://rpy.sourceforge.net/rpy2/doc/html/robjects.html#functions">described</a> in the docs, and call R directly for the functions. Also remember that RPy2 exp... | 7 | 2010-01-24T03:13:26Z | [
"python",
"rpy2"
] |
Python and Rpy2: Calling plot function with options that have "." in them | 2,125,218 | <p>I'm just starting to learn how to use rpy2 with python. I'm able to make simple plots and such, but I've run into the problem that many options in R use ".". For example, here's an R call that works:</p>
<blockquote>
<p>barplot(t, col=heat.colors(2), names.arg=c("pwn", "pwn2"))</p>
</blockquote>
<p>where t is ... | 8 | 2010-01-23T23:36:47Z | 2,141,984 | <p>With rpy2-2.1.0, one way to write it would be:</p>
<pre><code>from rpy2.robjects.packages import importr
graphics = importr("graphics")
grdevices = importr("grDevices")
graphics.barplot_default(t,
col = grdevices.heat_colors(2),
names_arg = StrVector(("pwn", "pwn2... | 0 | 2010-01-26T19:27:00Z | [
"python",
"rpy2"
] |
How to play sound in Python WITHOUT interrupting music/other sounds from playing | 2,125,547 | <p>I'm working on a timer in python which sounds a chime when the waiting time is over. I use the following code:</p>
<pre><code>from wave import open as wave_open
from ossaudiodev import open as oss_open
def _play_chime():
"""
Play a sound file once.
"""
sound_file = wave_open('chime.wav','rb')
... | 7 | 2010-01-24T01:40:38Z | 2,125,558 | <p>The easy answer is "Switch from OSS to PulseAudio." (Or set up ALSA to use dmix, or get a soundcard with better Linux drivers...)</p>
<p>The more complicated answer is, your code already works the way you want it to... on some soundcards. OSS drivers can expose hardware mixers so that you can have multiple audio st... | 8 | 2010-01-24T01:45:08Z | [
"python",
"linux",
"audio",
"timer"
] |
How to play sound in Python WITHOUT interrupting music/other sounds from playing | 2,125,547 | <p>I'm working on a timer in python which sounds a chime when the waiting time is over. I use the following code:</p>
<pre><code>from wave import open as wave_open
from ossaudiodev import open as oss_open
def _play_chime():
"""
Play a sound file once.
"""
sound_file = wave_open('chime.wav','rb')
... | 7 | 2010-01-24T01:40:38Z | 2,127,154 | <p>Modern hardware and drivers supports multiple streams. So unless you are running with ancient hardware or a crappy driver, it should work anyway.</p>
<p>Having said that, ALSA may give you more control than OSS. Most kernels shipped nowadays support both.</p>
| 1 | 2010-01-24T13:11:18Z | [
"python",
"linux",
"audio",
"timer"
] |
What are the advantages of using Django insead of app-engine's default web framework? | 2,125,612 | <p>I'm building my first python app on app-engine and wondering if I should use Django or not. </p>
<p>What are the strong points of each? If you have references that support your answer, please post them. Maybe we can make a wiki out of this question.</p>
| 7 | 2010-01-24T02:07:36Z | 2,125,658 | <p>Aral Balkan wrote <a href="http://aralbalkan.com/1313">a really nice piece</a> addressing this very question. Its a year or so old, so take it with a grain of salt - I think that a lot more emphasis should be put on the awesomeness of django's Object-Relational-Model. Basically, IMHO, it all comes down to whether or... | 5 | 2010-01-24T02:24:22Z | [
"python",
"django",
"google-app-engine"
] |
What are the advantages of using Django insead of app-engine's default web framework? | 2,125,612 | <p>I'm building my first python app on app-engine and wondering if I should use Django or not. </p>
<p>What are the strong points of each? If you have references that support your answer, please post them. Maybe we can make a wiki out of this question.</p>
| 7 | 2010-01-24T02:07:36Z | 2,129,141 | <p>If it's not a small project, I try to use Django. You can use the App Engine Patch (http://code.google.com/p/app-engine-patch/). However, the ORM cannot use Django's meaning your models.py will still be using GAE's Datastore.</p>
<p>One of the advantages of using Django on GAE is session management. GAE does not ha... | 1 | 2010-01-24T22:24:11Z | [
"python",
"django",
"google-app-engine"
] |
How to suppress console output in Python? | 2,125,702 | <p>I'm using Pygame/SDL's joystick module to get input from a gamepad. Every time I call its <code>get_hat()</code> method it prints to the console. This is problematic since I use the console to help me debug and now it gets flooded with <code>SDL_JoystickGetHat value:0:</code> 60 times every second. Is there a way I ... | 13 | 2010-01-24T02:43:59Z | 2,125,776 | <p>You can get around this by assigning the standard out/error (I don't know which one it's going to) to the null device. In Python, the standard out/error files are <code>sys.stdout</code>/<code>sys.stderr</code>, and the null device is <code>os.devnull</code>, so you do</p>
<pre><code>sys.stdout = os.devnull
sys.std... | 10 | 2010-01-24T03:16:54Z | [
"python",
"sdl",
"pygame"
] |
How to suppress console output in Python? | 2,125,702 | <p>I'm using Pygame/SDL's joystick module to get input from a gamepad. Every time I call its <code>get_hat()</code> method it prints to the console. This is problematic since I use the console to help me debug and now it gets flooded with <code>SDL_JoystickGetHat value:0:</code> 60 times every second. Is there a way I ... | 13 | 2010-01-24T02:43:59Z | 2,125,827 | <p>Here's the relevant block of code from joystick.c (via SVN at <a href="http://svn.seul.org/viewcvs/viewvc.cgi/trunk/src/joystick.c?view=markup&revision=2652&root=PyGame" rel="nofollow">http://svn.seul.org/viewcvs/viewvc.cgi/trunk/src/joystick.c?view=markup&revision=2652&root=PyGame</a>)</p>
<pre><co... | 3 | 2010-01-24T03:42:43Z | [
"python",
"sdl",
"pygame"
] |
How to suppress console output in Python? | 2,125,702 | <p>I'm using Pygame/SDL's joystick module to get input from a gamepad. Every time I call its <code>get_hat()</code> method it prints to the console. This is problematic since I use the console to help me debug and now it gets flooded with <code>SDL_JoystickGetHat value:0:</code> 60 times every second. Is there a way I ... | 13 | 2010-01-24T02:43:59Z | 5,063,983 | <p>I use pythonw.exe (on Windows) instead of python.exe.
In other OSes, you could also redirect output to /dev/nul.
And in order to still see my debug output, I am using the logging module.</p>
| 1 | 2011-02-21T09:00:31Z | [
"python",
"sdl",
"pygame"
] |
How to suppress console output in Python? | 2,125,702 | <p>I'm using Pygame/SDL's joystick module to get input from a gamepad. Every time I call its <code>get_hat()</code> method it prints to the console. This is problematic since I use the console to help me debug and now it gets flooded with <code>SDL_JoystickGetHat value:0:</code> 60 times every second. Is there a way I ... | 13 | 2010-01-24T02:43:59Z | 13,548,414 | <p>As <a href="http://stackoverflow.com/users/776788/demolishun">Demolishun</a> mentions in an <a href="http://stackoverflow.com/questions/7012444/disable-the-pygame-console-output">answer</a> to a closed duplicate question, there is a <a href="http://stackoverflow.com/questions/7012444/disable-the-pygame-console-outpu... | 1 | 2012-11-25T04:54:31Z | [
"python",
"sdl",
"pygame"
] |
How to suppress console output in Python? | 2,125,702 | <p>I'm using Pygame/SDL's joystick module to get input from a gamepad. Every time I call its <code>get_hat()</code> method it prints to the console. This is problematic since I use the console to help me debug and now it gets flooded with <code>SDL_JoystickGetHat value:0:</code> 60 times every second. Is there a way I ... | 13 | 2010-01-24T02:43:59Z | 25,061,573 | <p>Just for completeness, here's a nice solution from <a href="http://thesmithfam.org/blog/2012/10/25/temporarily-suppress-console-output-in-python/">Dave Smith's blog</a>:</p>
<pre><code>from contextlib import contextmanager
import sys, os
@contextmanager
def suppress_stdout():
with open(os.devnull, "w") as devn... | 11 | 2014-07-31T14:31:13Z | [
"python",
"sdl",
"pygame"
] |
How to suppress console output in Python? | 2,125,702 | <p>I'm using Pygame/SDL's joystick module to get input from a gamepad. Every time I call its <code>get_hat()</code> method it prints to the console. This is problematic since I use the console to help me debug and now it gets flooded with <code>SDL_JoystickGetHat value:0:</code> 60 times every second. Is there a way I ... | 13 | 2010-01-24T02:43:59Z | 36,648,314 | <p>If you are on a Debian or Ubuntu machine you can just simply recompile pygame without the messages. </p>
<pre><code>cd /tmp
sudo apt-get build-dep pygame
apt-get source pygame
vim pygame-1.9.1release+dfsg/src/joystick.c
# search for the printf("SDL.. messages and put a // in front
apt-get source --compile pygame
su... | 0 | 2016-04-15T13:18:47Z | [
"python",
"sdl",
"pygame"
] |
How to properly escape output (for XHTML) in mako? | 2,125,788 | <p>Despite offering a nice way to escape output using filters, none of them do the right thing.
Taking the string:</p>
<pre><code>x=u"&\u0092"
</code></pre>
<p>The filters do the following:</p>
<pre><code>x Turns the & into an entity but not the \u0092 (valid XML but not XHTML)
h Exac... | 3 | 2010-01-24T03:23:34Z | 2,125,816 | <p>It is not necessary to convert Unicode characters to the <code>&#xxxx;</code> form to work in HTML unless you're deliberately using the ASCII charset. It's simpler and more efficient to escape named entities, then encode the whole string to UTF-8 and write it out like that. You should probably declare the encodi... | 2 | 2010-01-24T03:40:11Z | [
"python",
"xhtml",
"unicode",
"escaping",
"mako"
] |
How to properly escape output (for XHTML) in mako? | 2,125,788 | <p>Despite offering a nice way to escape output using filters, none of them do the right thing.
Taking the string:</p>
<pre><code>x=u"&\u0092"
</code></pre>
<p>The filters do the following:</p>
<pre><code>x Turns the & into an entity but not the \u0092 (valid XML but not XHTML)
h Exac... | 3 | 2010-01-24T03:23:34Z | 2,126,054 | <p>Validation issues aside, it's useful to be able to remove these characters (which don't display reliably anyway) <em>without</em> necessarily escaping anything else. To this end I added the following function to `lib/helpers.py':</p>
<pre><code>__sgml_invalid = re.compile(r'[\x82-\x8c\x91-\x9c\x9f]', re.UNICODE)
d... | 1 | 2010-01-24T05:17:11Z | [
"python",
"xhtml",
"unicode",
"escaping",
"mako"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.