title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
How to use time > year 2038 on official Windows Python 2.5 | 839,755 | <p>The official Python 2.5 on Windows was build with Visual Studio.Net 2003, which uses 32 bit time_t. So when the year is > 2038, it just gives exceptions.</p>
<p>Although this is fixed in Python 2.6 (which changed time_t to 64 bit with VS2008), I'd like to use 2.5 because many modules are already compiled for it.</p... | 5 | 2009-05-08T13:19:17Z | 1,865,730 | <p>The best solution I've found is to get a source copy of Python 2.5, and re-compile the time module with compilers which defaults time_t to 64 bit, for example VS2005 or VS2008 (may also configure the C runtime to prevent side-by-side issue).</p>
| 3 | 2009-12-08T09:17:53Z | [
"python",
"time",
"python-2.5",
"time-t",
"year2038"
] |
Extracting a URL in Python | 839,994 | <p>In regards to: <a href="http://stackoverflow.com/questions/720113/find-hyperlinks-in-text-using-python-twitter-related">http://stackoverflow.com/questions/720113/find-hyperlinks-in-text-using-python-twitter-related</a></p>
<p>How can I extract just the url so I can put it into a list/array?</p>
<p><hr /></p>
<h2>... | 6 | 2009-05-08T14:17:04Z | 840,014 | <p>Misunderstood question:</p>
<pre><code>>>> from urllib.parse import urlparse
>>> urlparse('http://www.ggogle.com/test?t')
ParseResult(scheme='http', netloc='www.ggogle.com', path='/test',
params='', query='t', fragment='')
</code></pre>
<p><a href="http://docs.python.org/library/urlparse.... | 15 | 2009-05-08T14:20:51Z | [
"python",
"url",
"parsing"
] |
Extracting a URL in Python | 839,994 | <p>In regards to: <a href="http://stackoverflow.com/questions/720113/find-hyperlinks-in-text-using-python-twitter-related">http://stackoverflow.com/questions/720113/find-hyperlinks-in-text-using-python-twitter-related</a></p>
<p>How can I extract just the url so I can put it into a list/array?</p>
<p><hr /></p>
<h2>... | 6 | 2009-05-08T14:17:04Z | 840,110 | <p>In response to the OP's edit I hijacked <a href="http://stackoverflow.com/questions/720113/find-hyperlinks-in-text-using-python-twitter-related">Find Hyperlinks in Text using Python (twitter related)</a> and came up with this:</p>
<pre><code>import re
myString = "This is my tweet check it out http://tinyurl.com/bl... | 14 | 2009-05-08T14:39:32Z | [
"python",
"url",
"parsing"
] |
Extracting a URL in Python | 839,994 | <p>In regards to: <a href="http://stackoverflow.com/questions/720113/find-hyperlinks-in-text-using-python-twitter-related">http://stackoverflow.com/questions/720113/find-hyperlinks-in-text-using-python-twitter-related</a></p>
<p>How can I extract just the url so I can put it into a list/array?</p>
<p><hr /></p>
<h2>... | 6 | 2009-05-08T14:17:04Z | 2,965,647 | <p>Regarding this:</p>
<pre><code>import re
myString = "This is my tweet check it out http:// tinyurl.com/blah"
print re.search("(?P<url>https?://[^\s]+)", myString).group("url")
</code></pre>
<p>It won't work well if you have multiple urls in the string.
If the string looks like:</p>
<pre><code>myString = "Th... | 2 | 2010-06-03T11:55:20Z | [
"python",
"url",
"parsing"
] |
Extracting a URL in Python | 839,994 | <p>In regards to: <a href="http://stackoverflow.com/questions/720113/find-hyperlinks-in-text-using-python-twitter-related">http://stackoverflow.com/questions/720113/find-hyperlinks-in-text-using-python-twitter-related</a></p>
<p>How can I extract just the url so I can put it into a list/array?</p>
<p><hr /></p>
<h2>... | 6 | 2009-05-08T14:17:04Z | 10,907,680 | <p>Don't forget to check for whether the search returns a value of <code>None</code>âI found the posts above helpful but wasted time dealing with a <code>None</code> result.</p>
<p>See <a href="http://stackoverflow.com/questions/1491277/python-regex-object-has-no-attribute">Python Regex "object has no attribute... | 1 | 2012-06-06T03:09:09Z | [
"python",
"url",
"parsing"
] |
Extracting a URL in Python | 839,994 | <p>In regards to: <a href="http://stackoverflow.com/questions/720113/find-hyperlinks-in-text-using-python-twitter-related">http://stackoverflow.com/questions/720113/find-hyperlinks-in-text-using-python-twitter-related</a></p>
<p>How can I extract just the url so I can put it into a list/array?</p>
<p><hr /></p>
<h2>... | 6 | 2009-05-08T14:17:04Z | 27,753,723 | <p>[note: Assuming you are using this on Twitter data (as indicated in question), the simplest way of doing this is to use their API, which returns the urls extracted from tweets as a field]</p>
| 0 | 2015-01-03T10:10:12Z | [
"python",
"url",
"parsing"
] |
Extracting a URL in Python | 839,994 | <p>In regards to: <a href="http://stackoverflow.com/questions/720113/find-hyperlinks-in-text-using-python-twitter-related">http://stackoverflow.com/questions/720113/find-hyperlinks-in-text-using-python-twitter-related</a></p>
<p>How can I extract just the url so I can put it into a list/array?</p>
<p><hr /></p>
<h2>... | 6 | 2009-05-08T14:17:04Z | 28,552,735 | <p>Here's a file with a huge regex:</p>
<pre><code>#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
the web url matching regex used by markdown
http://daringfireball.net/2010/07/improved_regex_for_matching_urls
https://gist.github.com/gruber/8891611
"""
URL_REGEX = r"""(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.... | 2 | 2015-02-17T00:26:43Z | [
"python",
"url",
"parsing"
] |
Popen log management question | 840,531 | <p><strong>Problem:</strong></p>
<p>I have a monitor program in Python that uses subprocess' Popen to start new processes. These processes have the potential to run for a very long time (weeks-months). I'm passing a file handle to stdout variable in Popen and I'm worried that this file will get huge easily. Is ther... | 0 | 2009-05-08T15:57:32Z | 840,769 | <p>Fix the monitor program so that it is responsible for rotating its own logs, or mediate the data coming from the log program yourself and package it out into separate files.</p>
<p>Those are the two options you have. You can't mess with another process' file descriptors once it's running, so no, you can't "move or... | 1 | 2009-05-08T16:46:19Z | [
"python",
"logging",
"popen"
] |
Sort lexicographically? | 840,637 | <p>I am working on integrating with the Photobucket API and I came across this in their <a href="http://pic.photobucket.com/dev%5Fhelp/WebHelpPublic/Content/Getting%20Started/Consumer%20Authentication.htm">api docs</a>:</p>
<blockquote>
<p><em>"Sort the parameters by name
lexographically [sic] (byte ordering, the
... | 7 | 2009-05-08T16:18:50Z | 840,654 | <p>The word should be "lexicographic"</p>
<p><a href="http://www.thefreedictionary.com/Lexicographic">http://www.thefreedictionary.com/Lexicographic</a></p>
<p>Dictionary order. Using the letters as they appear in the strings. </p>
<p>As they suggest, don't fold upper- and lower-case together. Just use the Python ... | 6 | 2009-05-08T16:24:16Z | [
"python",
"api",
"sorting",
"photobucket"
] |
Sort lexicographically? | 840,637 | <p>I am working on integrating with the Photobucket API and I came across this in their <a href="http://pic.photobucket.com/dev%5Fhelp/WebHelpPublic/Content/Getting%20Started/Consumer%20Authentication.htm">api docs</a>:</p>
<blockquote>
<p><em>"Sort the parameters by name
lexographically [sic] (byte ordering, the
... | 7 | 2009-05-08T16:18:50Z | 840,695 | <p>This is similar to the Facebook API â the query string needs to be normalized before generating the signature hash.</p>
<p>You probably have a dictionary of parameters like:</p>
<pre><code>params = {
'consumer_key': "....",
'consumer_secret': "....",
'timestamp': ...,
...
}
</code></pre>
<p>Create the ... | 4 | 2009-05-08T16:31:46Z | [
"python",
"api",
"sorting",
"photobucket"
] |
Sort lexicographically? | 840,637 | <p>I am working on integrating with the Photobucket API and I came across this in their <a href="http://pic.photobucket.com/dev%5Fhelp/WebHelpPublic/Content/Getting%20Started/Consumer%20Authentication.htm">api docs</a>:</p>
<blockquote>
<p><em>"Sort the parameters by name
lexographically [sic] (byte ordering, the
... | 7 | 2009-05-08T16:18:50Z | 840,727 | <p>I think that here lexicographic is a "alias" for ascii sort?</p>
<pre>
Lexicographic Natural
z1.doc z1.doc
z10.doc z2.doc
z100.doc z3.doc
z101.doc z4.doc
z102.doc z5.doc
z11.doc z6.doc
z1... | 7 | 2009-05-08T16:38:46Z | [
"python",
"api",
"sorting",
"photobucket"
] |
Sort lexicographically? | 840,637 | <p>I am working on integrating with the Photobucket API and I came across this in their <a href="http://pic.photobucket.com/dev%5Fhelp/WebHelpPublic/Content/Getting%20Started/Consumer%20Authentication.htm">api docs</a>:</p>
<blockquote>
<p><em>"Sort the parameters by name
lexographically [sic] (byte ordering, the
... | 7 | 2009-05-08T16:18:50Z | 840,896 | <p>Quote a bit more from the section:</p>
<blockquote>
<p>2 Generate the Base String:</p>
<p>Normalize the parameters:</p>
<ul>
<li><p>Add the OAuth specific parameters for this request to the input parameters, including:</p>
<pre><code>oauth_consumer_key = <consumer_key>
oauth_timestamp = <ti... | 1 | 2009-05-08T17:16:22Z | [
"python",
"api",
"sorting",
"photobucket"
] |
How do you alias a python class to have another name without using inheritance? | 840,969 | <p>If I have a python class, how can I alias that class-name into another class-name and retain all it's methods and class members and instance members? Is this possible without using inheritance?</p>
<p>e.g. I have a class like:</p>
<pre><code>class MyReallyBigClassNameWhichIHateToType:
def __init__(self):
... | 25 | 2009-05-08T17:35:18Z | 840,976 | <p>Refactor the name, no reason it should have a name that long.</p>
<p>Otherwise <code>whateverName = VeryLongClassName</code> should do the trick.</p>
| 7 | 2009-05-08T17:36:56Z | [
"python"
] |
How do you alias a python class to have another name without using inheritance? | 840,969 | <p>If I have a python class, how can I alias that class-name into another class-name and retain all it's methods and class members and instance members? Is this possible without using inheritance?</p>
<p>e.g. I have a class like:</p>
<pre><code>class MyReallyBigClassNameWhichIHateToType:
def __init__(self):
... | 25 | 2009-05-08T17:35:18Z | 840,977 | <pre><code>C = MyReallyBigClassNameWhichIHateToType
</code></pre>
| 50 | 2009-05-08T17:37:11Z | [
"python"
] |
How do you alias a python class to have another name without using inheritance? | 840,969 | <p>If I have a python class, how can I alias that class-name into another class-name and retain all it's methods and class members and instance members? Is this possible without using inheritance?</p>
<p>e.g. I have a class like:</p>
<pre><code>class MyReallyBigClassNameWhichIHateToType:
def __init__(self):
... | 25 | 2009-05-08T17:35:18Z | 840,979 | <p>You can simply do:</p>
<pre><code>ShortName = MyReallyBigClassNameWhichIHateToType
</code></pre>
<p>A class in Python is just an object like any other, and can have more than one names.</p>
| 10 | 2009-05-08T17:37:33Z | [
"python"
] |
How do you alias a python class to have another name without using inheritance? | 840,969 | <p>If I have a python class, how can I alias that class-name into another class-name and retain all it's methods and class members and instance members? Is this possible without using inheritance?</p>
<p>e.g. I have a class like:</p>
<pre><code>class MyReallyBigClassNameWhichIHateToType:
def __init__(self):
... | 25 | 2009-05-08T17:35:18Z | 841,007 | <p>Also, if you're importing the name from another module...</p>
<pre><code>from modulename import ReallyLongNameWhichIHateToType as FriendlyName
</code></pre>
| 23 | 2009-05-08T17:45:39Z | [
"python"
] |
Computing the second (mis-match) table in the Boyer-Moore String Search Algorithm | 840,974 | <p>For the Boyer-Moore algorithm to be worst-case linear, the computation of the mis-match table must be O(m). However, a naive implementation would loop through all suffixs O(m) and all positions in that that suffix could go and check for equality... which is O(m<sup>3</sup>)!</p>
<p>Below is the naive implementation... | 4 | 2009-05-08T17:36:32Z | 843,443 | <p>The code under "Preprocessing for the good-suffix heuristics" on <a href="http://www.iti.fh-flensburg.de/lang/algorithmen/pattern/bmen.htm" rel="nofollow">this page</a> builds the good-suffix table in O(n) time. It also explains how the code works.</p>
| 1 | 2009-05-09T14:50:32Z | [
"python",
"algorithm",
"discrete-mathematics",
"string-search"
] |
How do you store raw bytes as text without losing information in python 2.x? | 840,981 | <p>Suppose I have any data stored in bytes. For example:</p>
<blockquote>
<p>0110001100010101100101110101101</p>
</blockquote>
<p>How can I store it as <em>printable</em> text? The obvious way would be to convert every 0 to the character '0' and every 1 to the character '1'. In fact this is what I'm currently doi... | 1 | 2009-05-08T17:37:43Z | 840,988 | <p>Try the standard <em>array</em> module or the <em>struct</em> module. These support storing bytes in a space efficient way -- but they don't support bits directly.</p>
<p>You can also try <a href="http://cobweb.ecn.purdue.edu/~kak/dist/BitVector-1.2.html" rel="nofollow">http://cobweb.ecn.purdue.edu/~kak/dist/BitVec... | 1 | 2009-05-08T17:40:38Z | [
"python",
"python-2.7",
"storage",
"bit",
"data-compression"
] |
How do you store raw bytes as text without losing information in python 2.x? | 840,981 | <p>Suppose I have any data stored in bytes. For example:</p>
<blockquote>
<p>0110001100010101100101110101101</p>
</blockquote>
<p>How can I store it as <em>printable</em> text? The obvious way would be to convert every 0 to the character '0' and every 1 to the character '1'. In fact this is what I'm currently doi... | 1 | 2009-05-08T17:37:43Z | 840,994 | <p>What about an encodeing that only uses "safe" charectors like base64?<br />
<a href="http://en.wikipedia.org/wiki/Base64" rel="nofollow">http://en.wikipedia.org/wiki/Base64</a></p>
<p>EDIT: That is assumeing you want to safey store the data in text files and such?</p>
<p>In 2.x strings should be fine (python doesn... | 7 | 2009-05-08T17:43:02Z | [
"python",
"python-2.7",
"storage",
"bit",
"data-compression"
] |
How do you store raw bytes as text without losing information in python 2.x? | 840,981 | <p>Suppose I have any data stored in bytes. For example:</p>
<blockquote>
<p>0110001100010101100101110101101</p>
</blockquote>
<p>How can I store it as <em>printable</em> text? The obvious way would be to convert every 0 to the character '0' and every 1 to the character '1'. In fact this is what I'm currently doi... | 1 | 2009-05-08T17:37:43Z | 841,016 | <p>Not sure what you're talking about.</p>
<pre><code>>>> sample = "".join( chr(c) for c in range(256) )
>>> len(sample)
256
>>> sample
'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\
x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./0123456789:... | 2 | 2009-05-08T17:47:18Z | [
"python",
"python-2.7",
"storage",
"bit",
"data-compression"
] |
How do you store raw bytes as text without losing information in python 2.x? | 840,981 | <p>Suppose I have any data stored in bytes. For example:</p>
<blockquote>
<p>0110001100010101100101110101101</p>
</blockquote>
<p>How can I store it as <em>printable</em> text? The obvious way would be to convert every 0 to the character '0' and every 1 to the character '1'. In fact this is what I'm currently doi... | 1 | 2009-05-08T17:37:43Z | 846,491 | <p>For Python 2.x, your best bet is to store them in a string. Once you have that string, you can encode it into safe ASCII values using the base64 module that comes with python.</p>
<pre><code>import base64
encoded = base64.b64encode(bytestring)
</code></pre>
<p>This will be much more condensed than storing "1" and ... | 0 | 2009-05-11T02:01:39Z | [
"python",
"python-2.7",
"storage",
"bit",
"data-compression"
] |
How to edit raw PCM audio data without an audio library? | 841,049 | <p>I'm interested in precisely extracting portions of a PCM WAV file, down to the sample level. Most audio modules seem to rely on platform-specific audio libraries. I want to make this cross platform and speed is not an issue, are there any native python audio modules that can do this?</p>
<p>If not, I'll have to i... | 7 | 2009-05-08T17:57:25Z | 841,097 | <p>Is it really important that your solution be pure Python, or would you accept something that can work with native audio libraries on various platforms (so it's effectively cross-platform)? There are several examples of the latter at <a href="http://wiki.python.org/moin/PythonInMusic" rel="nofollow">http://wiki.pytho... | 1 | 2009-05-08T18:11:09Z | [
"python",
"audio",
"binary",
"wav"
] |
How to edit raw PCM audio data without an audio library? | 841,049 | <p>I'm interested in precisely extracting portions of a PCM WAV file, down to the sample level. Most audio modules seem to rely on platform-specific audio libraries. I want to make this cross platform and speed is not an issue, are there any native python audio modules that can do this?</p>
<p>If not, I'll have to i... | 7 | 2009-05-08T17:57:25Z | 841,135 | <p>Seems like a combination of open(..., "rb"), <a href="http://docs.python.org/library/struct.html" rel="nofollow">struct module</a>, and some details about the <a href="http://ccrma.stanford.edu/courses/422/projects/WaveFormat/" rel="nofollow">wav/riff file format</a> (probably better reference out there) will do the... | 1 | 2009-05-08T18:20:07Z | [
"python",
"audio",
"binary",
"wav"
] |
How to edit raw PCM audio data without an audio library? | 841,049 | <p>I'm interested in precisely extracting portions of a PCM WAV file, down to the sample level. Most audio modules seem to rely on platform-specific audio libraries. I want to make this cross platform and speed is not an issue, are there any native python audio modules that can do this?</p>
<p>If not, I'll have to i... | 7 | 2009-05-08T17:57:25Z | 841,175 | <p>I've only written a PCM reader in C++ and Java, but the format itself is fairly simple. A decent description can be found here: <a href="http://ccrma.stanford.edu/courses/422/projects/WaveFormat/" rel="nofollow">http://ccrma.stanford.edu/courses/422/projects/WaveFormat/</a></p>
<p>Past that you should be able to ju... | 5 | 2009-05-08T18:28:15Z | [
"python",
"audio",
"binary",
"wav"
] |
How to edit raw PCM audio data without an audio library? | 841,049 | <p>I'm interested in precisely extracting portions of a PCM WAV file, down to the sample level. Most audio modules seem to rely on platform-specific audio libraries. I want to make this cross platform and speed is not an issue, are there any native python audio modules that can do this?</p>
<p>If not, I'll have to i... | 7 | 2009-05-08T17:57:25Z | 841,363 | <p>I read the question and the answers and I feel that I must be missing something completely obvious, because nobody mentioned the following two modules:</p>
<ul>
<li><a href="https://docs.python.org/library/audioop.html" rel="nofollow">audioop</a>: manipulate raw audio data</li>
<li><a href="https://docs.python.org/... | 6 | 2009-05-08T19:15:37Z | [
"python",
"audio",
"binary",
"wav"
] |
How to edit raw PCM audio data without an audio library? | 841,049 | <p>I'm interested in precisely extracting portions of a PCM WAV file, down to the sample level. Most audio modules seem to rely on platform-specific audio libraries. I want to make this cross platform and speed is not an issue, are there any native python audio modules that can do this?</p>
<p>If not, I'll have to i... | 7 | 2009-05-08T17:57:25Z | 31,684,721 | <p>I was looking this up and I found this: <a href="http://www.swharden.com/blog/2009-06-19-reading-pcm-audio-with-python/" rel="nofollow">http://www.swharden.com/blog/2009-06-19-reading-pcm-audio-with-python/</a>
It requires Numpy (and matplotlib if you want to graph it) </p>
<pre><code>import numpy
data = numpy.memm... | 0 | 2015-07-28T18:46:59Z | [
"python",
"audio",
"binary",
"wav"
] |
mod_python publisher and pretty URLs | 841,068 | <p>I am new to Python (I am getting out of PHP because of how increasingly broken it is), and I am racing through porting my old code. One thing:</p>
<p>I have a file /foo.py with functions index() and bar(), so, with the publisher I can access <a href="http://domain/foo/bar" rel="nofollow">http://domain/foo/bar</a> a... | 1 | 2009-05-08T18:03:22Z | 841,110 | <p>You would have to have an object <code>bar.a1.a2.a3.an</code> defined within your <code>foo.py</code> module. Basically, the publisher handler replaces the slashes in the URL with dots, and tries to find some Python object with that name.</p>
<p>You would have to have an object <code>bar.a1.a2.a3.an</code> defined ... | 1 | 2009-05-08T18:14:46Z | [
"python",
"url",
"mod-python",
"friendly-url"
] |
mod_python publisher and pretty URLs | 841,068 | <p>I am new to Python (I am getting out of PHP because of how increasingly broken it is), and I am racing through porting my old code. One thing:</p>
<p>I have a file /foo.py with functions index() and bar(), so, with the publisher I can access <a href="http://domain/foo/bar" rel="nofollow">http://domain/foo/bar</a> a... | 1 | 2009-05-08T18:03:22Z | 841,120 | <p>I believe this is beyond the capabilities of the publishing algorithm, as far as I know. (<a href="http://www.modpython.org/live/mod%5Fpython-3.3.1/doc-html/hand-pub-alg-trav.html" rel="nofollow">The documentation certainly doesn't mention it.</a>) You could write your own mod_python handler (<a href="http://www.mod... | 1 | 2009-05-08T18:17:27Z | [
"python",
"url",
"mod-python",
"friendly-url"
] |
Tokenizing left over data with lex/yacc | 841,159 | <p>Forgive me, I'm completely new to parsing and lex/yacc, and I'm probably in way over my head, but nonetheless:</p>
<p>I'm writing a pretty basic calculator with PLY, but it's input might not always be an equation, and I need to determine if it is or not when parsing. The extremes of the input would be something tha... | 3 | 2009-05-08T18:23:39Z | 842,248 | <p>There is a built-in <code>error</code> token in yacc. You would normally do something like:</p>
<p><code></p>
<p>line: goodline | badline ;</p>
<p>badline : error '\n' /* Error-handling action, if needed */</p>
<p>goodline : equation '\n' ;
</code></p>
<p>Any line that doesn't match <code>equation</code> will b... | 1 | 2009-05-08T23:33:39Z | [
"python",
"yacc",
"lex",
"ply"
] |
Tokenizing left over data with lex/yacc | 841,159 | <p>Forgive me, I'm completely new to parsing and lex/yacc, and I'm probably in way over my head, but nonetheless:</p>
<p>I'm writing a pretty basic calculator with PLY, but it's input might not always be an equation, and I need to determine if it is or not when parsing. The extremes of the input would be something tha... | 3 | 2009-05-08T18:23:39Z | 842,331 | <p>I typically use a separate 'command reader' to obtain a complete command - probably a line in your case - into a host variable string, and then arrange for the lexical analyzer to analyze the string, including telling me when it didn't reach the end. This is hard to set up, but make some classes of error reporting ... | 0 | 2009-05-09T00:06:45Z | [
"python",
"yacc",
"lex",
"ply"
] |
Tokenizing left over data with lex/yacc | 841,159 | <p>Forgive me, I'm completely new to parsing and lex/yacc, and I'm probably in way over my head, but nonetheless:</p>
<p>I'm writing a pretty basic calculator with PLY, but it's input might not always be an equation, and I need to determine if it is or not when parsing. The extremes of the input would be something tha... | 3 | 2009-05-08T18:23:39Z | 846,952 | <p>Define a token (end of input), and make your lexer output it at the end of the input.</p>
<p>So before, if you had these tokens:</p>
<pre><code>'1' 'PLUS' '1'
</code></pre>
<p>You'll now have:</p>
<pre><code>'1' 'PLUS' '1' 'END_OF_INPUT'
</code></pre>
<p>Now, you can define your top-level rule in your parser. I... | 1 | 2009-05-11T06:31:03Z | [
"python",
"yacc",
"lex",
"ply"
] |
Tokenizing left over data with lex/yacc | 841,159 | <p>Forgive me, I'm completely new to parsing and lex/yacc, and I'm probably in way over my head, but nonetheless:</p>
<p>I'm writing a pretty basic calculator with PLY, but it's input might not always be an equation, and I need to determine if it is or not when parsing. The extremes of the input would be something tha... | 3 | 2009-05-08T18:23:39Z | 853,186 | <p>It looks like you've already found a solution but I'll add another suggestion in case you or others are interested in an alternative approach.</p>
<p>You say you are using PLY but is that because you want the compiler to run in a Python environment? If so, you might consider other tools as well. For such jobs I o... | 0 | 2009-05-12T14:51:13Z | [
"python",
"yacc",
"lex",
"ply"
] |
wxPython: Drawing inside a ScrolledPanel | 841,425 | <p>I'm using a PaintDC to draw inside a ScrolledPanel. However, when I run the program, the scroll bars have no effect. They're the right size, but the picture doesn't move when you scroll with them.</p>
<p>I figured I may have to convert from logical to device coordinates. I tried <code>x=dc.LogicalToDeviceX(x)</code... | 1 | 2009-05-08T19:33:04Z | 841,466 | <p>Got it:</p>
<pre><code>(new_x,new_y)=self.CalcScrolledPosition((old_x,old_y))
</code></pre>
<p>Where <code>self</code> is the ScrolledPanel.</p>
| 1 | 2009-05-08T19:40:40Z | [
"python",
"wxpython",
"scroll"
] |
What's going on with the lambda expression in this python function? | 841,555 | <p>Why does this attempt at creating a list of curried functions not work? </p>
<pre><code>def p(x, num):
print x, num
def test():
a = []
for i in range(10):
a.append(lambda x: p (i, x))
return a
>>> myList = test()
>>> test[0]('test')
9 test
>>> test[5]('test')
9 t... | 5 | 2009-05-08T20:03:43Z | 841,588 | <p>In Python, variables created in loops and branches aren't scoped. All of the functions you're creating with <code>lambda</code> have a reference to the same <code>i</code> variable, which is set to <code>9</code> on the last iteration of the loop.</p>
<p>The solution is to create a function which returns a function... | 12 | 2009-05-08T20:12:59Z | [
"python",
"lambda"
] |
What's going on with the lambda expression in this python function? | 841,555 | <p>Why does this attempt at creating a list of curried functions not work? </p>
<pre><code>def p(x, num):
print x, num
def test():
a = []
for i in range(10):
a.append(lambda x: p (i, x))
return a
>>> myList = test()
>>> test[0]('test')
9 test
>>> test[5]('test')
9 t... | 5 | 2009-05-08T20:03:43Z | 842,838 | <p>I asked a similar question, and got two answers. One basically the same as the accepted answer here, and the other which is less clear but slightly more succint.</p>
<p><a href="http://stackoverflow.com/questions/728356/dynamically-creating-a-menu-in-tkinter-lambda-expressions">http://stackoverflow.com/questions/72... | 0 | 2009-05-09T06:51:09Z | [
"python",
"lambda"
] |
What's going on with the lambda expression in this python function? | 841,555 | <p>Why does this attempt at creating a list of curried functions not work? </p>
<pre><code>def p(x, num):
print x, num
def test():
a = []
for i in range(10):
a.append(lambda x: p (i, x))
return a
>>> myList = test()
>>> test[0]('test')
9 test
>>> test[5]('test')
9 t... | 5 | 2009-05-08T20:03:43Z | 842,842 | <p>Well you can also bind the i to an outer lambda for the lazy.</p>
<pre><code>def p(x, num):
print x, num
def test():
a = []
for i in range(10):
a.append((lambda i :lambda x: p (i, x))(i))
return a
</code></pre>
| 1 | 2009-05-09T06:58:26Z | [
"python",
"lambda"
] |
What's going on with the lambda expression in this python function? | 841,555 | <p>Why does this attempt at creating a list of curried functions not work? </p>
<pre><code>def p(x, num):
print x, num
def test():
a = []
for i in range(10):
a.append(lambda x: p (i, x))
return a
>>> myList = test()
>>> test[0]('test')
9 test
>>> test[5]('test')
9 t... | 5 | 2009-05-08T20:03:43Z | 15,839,049 | <p>I was always confused as to why this doesn't work. Thanks for the explanation, '<a href="http://stackoverflow.com/users/102704/a-paid-nerd">a paid nerd</a>'. I personally prefer this solution:</p>
<pre><code>for i in range(10):
a.append(lambda num, val_i=i: p (val_i, num))
</code></pre>
<p>Note the <code>val_i... | 1 | 2013-04-05T16:34:31Z | [
"python",
"lambda"
] |
python: can I extend the upper bound of the range() method? | 841,584 | <p>What is the upper bound of the range() function and how can I extend it, or alternately what's the best way to do this:</p>
<pre><code>for i in range(1,600851475143):
</code></pre>
| 3 | 2009-05-08T20:10:49Z | 841,589 | <p><code>range(1, 600851475143)</code> wants to generate a very large list in memory, and you'll get an out of memory error. To save memory, use <code>xrange</code> instead of <code>range</code>. Unfortunately, <code>xrange</code> doesn't work with large numbers (it's an implementation restriction) Example (raises Over... | 9 | 2009-05-08T20:13:01Z | [
"python"
] |
python: can I extend the upper bound of the range() method? | 841,584 | <p>What is the upper bound of the range() function and how can I extend it, or alternately what's the best way to do this:</p>
<pre><code>for i in range(1,600851475143):
</code></pre>
| 3 | 2009-05-08T20:10:49Z | 841,620 | <p>pts' answer led me to this in the xrange python docs:</p>
<blockquote>
<p>Note</p>
<p>xrange() is intended to be simple and
fast. Implementations may impose
restrictions to achieve this. The C
implementation of Python restricts all
arguments to native C longs (âshortâ
Python integers), and also... | 2 | 2009-05-08T20:23:17Z | [
"python"
] |
python: can I extend the upper bound of the range() method? | 841,584 | <p>What is the upper bound of the range() function and how can I extend it, or alternately what's the best way to do this:</p>
<pre><code>for i in range(1,600851475143):
</code></pre>
| 3 | 2009-05-08T20:10:49Z | 841,626 | <p>It depends on which version of Python you're using. I'm using 2.5.2 and xrange raises an OverflowError exception for large numbers. One solution is to write your own generator.</p>
<pre><code>def g(start, stop):
i = start
while i < stop:
yield i
i += 1
x = 1<<200
for i in g(x, x+... | 0 | 2009-05-08T20:25:18Z | [
"python"
] |
python: can I extend the upper bound of the range() method? | 841,584 | <p>What is the upper bound of the range() function and how can I extend it, or alternately what's the best way to do this:</p>
<pre><code>for i in range(1,600851475143):
</code></pre>
| 3 | 2009-05-08T20:10:49Z | 842,404 | <p>Have you considered just doing this? Or is there some reason you specifically need <code>range()</code>?</p>
<pre><code>x = 1
while x < 600851475143:
// some code
x += 1
</code></pre>
| 1 | 2009-05-09T00:45:27Z | [
"python"
] |
python: can I extend the upper bound of the range() method? | 841,584 | <p>What is the upper bound of the range() function and how can I extend it, or alternately what's the best way to do this:</p>
<pre><code>for i in range(1,600851475143):
</code></pre>
| 3 | 2009-05-08T20:10:49Z | 844,028 | <p>Here's an answer using <a href="http://docs.python.org/library/itertools.html" rel="nofollow"><code>itertools</code></a>. It's a little contrived, but it works:</p>
<pre><code>from itertools import repeat, count, izip
for i,_ in izip(count(1), repeat(1, 600851475143)):
...
</code></pre>
<p>Another answer woul... | 0 | 2009-05-09T20:47:19Z | [
"python"
] |
Pygame cannot find include file "sdl.h" | 841,654 | <p>I am trying to build a downloaded Python app on Windows that uses Pygame. I have installed Python 2.5 and Pygame 1.7.1. I am new to Python, but I just tried typing the name of the top level .py file on a Windows console command line. (I'm using Win XP Pro.)</p>
<p>This is the message that I get.</p>
<p><strong>... | 3 | 2009-05-08T20:31:04Z | 841,895 | <p>I tried compiling and got the same errors on my linux box:</p>
<pre><code>$ python setup.py build
DBG> include = ['/usr/include', '/usr/include/python2.6', '/usr/include/SDL']
running build
running build_ext
building 'surfutils' extension
creating build
creating build/temp.linux-i686-2.6
creating build/temp.linu... | 3 | 2009-05-08T21:28:59Z | [
"python",
"sdl",
"pygame"
] |
Pygame cannot find include file "sdl.h" | 841,654 | <p>I am trying to build a downloaded Python app on Windows that uses Pygame. I have installed Python 2.5 and Pygame 1.7.1. I am new to Python, but I just tried typing the name of the top level .py file on a Windows console command line. (I'm using Win XP Pro.)</p>
<p>This is the message that I get.</p>
<p><strong>... | 3 | 2009-05-08T20:31:04Z | 843,230 | <p>When you compile something the compiler looks up header files in several directories, some hardcoded and build in, and typically some given as arguments to the compiler (like for instance "gcc -I/usr/local/include ..."). One guess is that you are missing this. If not check out other possible causes to <a href="http:... | 1 | 2009-05-09T12:41:38Z | [
"python",
"sdl",
"pygame"
] |
Python: ODBC Exception Handling | 841,968 | <p>I need to recognize in my application whether table doesn't exist or has no rows to take appropriate action. Can I catch this two errors separately ?</p>
<pre><code>>>>cursor.execute("delete from TABLE")
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
dbi.i... | 0 | 2009-05-08T21:46:11Z | 842,023 | <p>From the <a href="http://www.python.org/doc/2.5/tut/node10.html" rel="nofollow">Python documentation</a>:</p>
<blockquote>
<p>A try statement may have more than one except clause, to specify handlers for different exceptions.</p>
</blockquote>
<p>For example:</p>
<pre><code>try:
do_something_crazy
except At... | 0 | 2009-05-08T22:04:56Z | [
"python",
"odbc"
] |
Django equivalent of COUNT with GROUP BY | 842,031 | <p>I know Django 1.1 has some new aggregation methods. However I couldn't figure out equivalent of the following query:</p>
<pre><code>SELECT player_type, COUNT(*) FROM players GROUP BY player_type;
</code></pre>
<p>Is it possible with Django 1.1's Model Query API or should I just use plain SQL?</p>
| 17 | 2009-05-08T22:08:32Z | 842,074 | <p>Django 1.1 does support aggregation methods like count. You can find <a href="http://docs.djangoproject.com/en/dev/topics/db/aggregation/">the full documentation here</a>.</p>
<p>To answer your question, you can use something along the lines of:</p>
<pre><code>from django.db.models import Count
q = Player.objects.... | 13 | 2009-05-08T22:25:40Z | [
"python",
"sql",
"django",
"django-queryset",
"django-aggregation"
] |
Django equivalent of COUNT with GROUP BY | 842,031 | <p>I know Django 1.1 has some new aggregation methods. However I couldn't figure out equivalent of the following query:</p>
<pre><code>SELECT player_type, COUNT(*) FROM players GROUP BY player_type;
</code></pre>
<p>Is it possible with Django 1.1's Model Query API or should I just use plain SQL?</p>
| 17 | 2009-05-08T22:08:32Z | 842,876 | <p>If you are using Django 1.1 beta (trunk):</p>
<pre><code>Player.objects.values('player_type').order_by().annotate(Count('player_type'))
</code></pre>
<ul>
<li><code>values('player_type')</code> - for inclusion only <code>player_type</code> field into <code>GROUP BY</code> clause.</li>
<li><code>order_by()</code> -... | 43 | 2009-05-09T07:40:12Z | [
"python",
"sql",
"django",
"django-queryset",
"django-aggregation"
] |
Is there a portable way to get the current username in Python? | 842,059 | <p>Is there a portable way to get the current user's username in Python (i.e., one that works under both Linux and Windows, at least). It would work like <code>os.getuid</code>:</p>
<pre><code>>>> os.getuid()
42
>>> os.getusername()
'slartibartfast'
</code></pre>
<p>I googled around and was surpris... | 361 | 2009-05-08T22:20:20Z | 842,096 | <p>Look at <a href="http://docs.python.org/library/getpass.html">getpass</a> module</p>
<pre><code>import getpass
getpass.getuser()
'kostya'
</code></pre>
<p>Availability: Unix, Windows</p>
<hr>
<p>p.s. Per comment below "<em>this function looks at the values of various environment variables to determine the user n... | 494 | 2009-05-08T22:30:51Z | [
"python",
"portability",
"username"
] |
Is there a portable way to get the current username in Python? | 842,059 | <p>Is there a portable way to get the current user's username in Python (i.e., one that works under both Linux and Windows, at least). It would work like <code>os.getuid</code>:</p>
<pre><code>>>> os.getuid()
42
>>> os.getusername()
'slartibartfast'
</code></pre>
<p>I googled around and was surpris... | 361 | 2009-05-08T22:20:20Z | 842,107 | <p>You can probably use:</p>
<pre><code>os.getenv('USERNAME')
</code></pre>
<p>But it's not going to be safe because environment variables can be changed.</p>
| 32 | 2009-05-08T22:35:54Z | [
"python",
"portability",
"username"
] |
Is there a portable way to get the current username in Python? | 842,059 | <p>Is there a portable way to get the current user's username in Python (i.e., one that works under both Linux and Windows, at least). It would work like <code>os.getuid</code>:</p>
<pre><code>>>> os.getuid()
42
>>> os.getusername()
'slartibartfast'
</code></pre>
<p>I googled around and was surpris... | 361 | 2009-05-08T22:20:20Z | 1,594,451 | <p>You can also use:</p>
<pre><code> os.getlogin()
</code></pre>
| 44 | 2009-10-20T13:00:12Z | [
"python",
"portability",
"username"
] |
Is there a portable way to get the current username in Python? | 842,059 | <p>Is there a portable way to get the current user's username in Python (i.e., one that works under both Linux and Windows, at least). It would work like <code>os.getuid</code>:</p>
<pre><code>>>> os.getuid()
42
>>> os.getusername()
'slartibartfast'
</code></pre>
<p>I googled around and was surpris... | 361 | 2009-05-08T22:20:20Z | 1,992,942 | <p>These might work. I don't know how they behave when running as a service. They aren't portable, but that's what "os.name" and "if" statements are for.</p>
<p>win32api.GetUserName()</p>
<p>win32api.GetUserNameEx(...) </p>
<p>See:
<a href="http://timgolden.me.uk/python/win32_how_do_i/get-the-owner-of-a-file.html"... | 14 | 2010-01-02T21:35:30Z | [
"python",
"portability",
"username"
] |
Is there a portable way to get the current username in Python? | 842,059 | <p>Is there a portable way to get the current user's username in Python (i.e., one that works under both Linux and Windows, at least). It would work like <code>os.getuid</code>:</p>
<pre><code>>>> os.getuid()
42
>>> os.getusername()
'slartibartfast'
</code></pre>
<p>I googled around and was surpris... | 361 | 2009-05-08T22:20:20Z | 2,202,690 | <p>I wrote the plx module some time ago to get the user name in a portable way on Unix and Windows (among other things):
<a href="http://www.decalage.info/en/python/plx">http://www.decalage.info/en/python/plx</a></p>
<p>Usage:</p>
<pre><code>import plx
username = plx.get_username()
</code></pre>
<p>(it requires win... | 5 | 2010-02-04T19:52:09Z | [
"python",
"portability",
"username"
] |
Is there a portable way to get the current username in Python? | 842,059 | <p>Is there a portable way to get the current user's username in Python (i.e., one that works under both Linux and Windows, at least). It would work like <code>os.getuid</code>:</p>
<pre><code>>>> os.getuid()
42
>>> os.getusername()
'slartibartfast'
</code></pre>
<p>I googled around and was surpris... | 361 | 2009-05-08T22:20:20Z | 2,899,055 | <p>You best bet would be to combine <code>os.getuid()</code> with <code>pwd.getpwuid()</code>:</p>
<pre><code>import os
import pwd
def get_username():
return pwd.getpwuid( os.getuid() )[ 0 ]
</code></pre>
<p>Refer to the pwd docs for more details:</p>
<p><a href="http://docs.python.org/library/pwd.html">http://... | 74 | 2010-05-24T17:53:51Z | [
"python",
"portability",
"username"
] |
Is there a portable way to get the current username in Python? | 842,059 | <p>Is there a portable way to get the current user's username in Python (i.e., one that works under both Linux and Windows, at least). It would work like <code>os.getuid</code>:</p>
<pre><code>>>> os.getuid()
42
>>> os.getusername()
'slartibartfast'
</code></pre>
<p>I googled around and was surpris... | 361 | 2009-05-08T22:20:20Z | 14,783,939 | <p>If you are needing this to get user's home dir, below could be considered as portable (win32 and linux at least), part of a standard library.</p>
<pre><code>>>> os.path.expanduser('~')
'C:\\Documents and Settings\\johnsmith'
</code></pre>
<p>Also you could parse such string to get only last path component... | 12 | 2013-02-09T01:23:29Z | [
"python",
"portability",
"username"
] |
Is there a portable way to get the current username in Python? | 842,059 | <p>Is there a portable way to get the current user's username in Python (i.e., one that works under both Linux and Windows, at least). It would work like <code>os.getuid</code>:</p>
<pre><code>>>> os.getuid()
42
>>> os.getusername()
'slartibartfast'
</code></pre>
<p>I googled around and was surpris... | 361 | 2009-05-08T22:20:20Z | 19,865,396 | <p>Combined <code>pwd</code> and <code>getpass</code> approach, based on other answers:</p>
<pre><code>try:
import pwd
except ImportError:
import getpass
pwd = None
def current_user():
if pwd:
return pwd.getpwuid(os.geteuid()).pw_name
else:
return getpass.getuser()
</code></pre>
| 7 | 2013-11-08T17:47:29Z | [
"python",
"portability",
"username"
] |
Is there a portable way to get the current username in Python? | 842,059 | <p>Is there a portable way to get the current user's username in Python (i.e., one that works under both Linux and Windows, at least). It would work like <code>os.getuid</code>:</p>
<pre><code>>>> os.getuid()
42
>>> os.getusername()
'slartibartfast'
</code></pre>
<p>I googled around and was surpris... | 361 | 2009-05-08T22:20:20Z | 20,090,568 | <p>You can get the current username on Windows by going through the Windows API, although it's a bit cumbersome to invoke via the ctypes FFI (<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms683179" rel="nofollow">GetCurrentProcess</a> â <a href="http://msdn.microsoft.com/en-us/library/aa379295" rel... | 3 | 2013-11-20T08:12:32Z | [
"python",
"portability",
"username"
] |
Is there a portable way to get the current username in Python? | 842,059 | <p>Is there a portable way to get the current user's username in Python (i.e., one that works under both Linux and Windows, at least). It would work like <code>os.getuid</code>:</p>
<pre><code>>>> os.getuid()
42
>>> os.getusername()
'slartibartfast'
</code></pre>
<p>I googled around and was surpris... | 361 | 2009-05-08T22:20:20Z | 20,402,832 | <p>To me using <code>os</code> module looks the best for portability: Works best on both Linux and Windows.</p>
<pre><code>import os
# Gives user's home directory
userhome = os.path.expanduser('~')
print "User's home Dir: " + userhome
# Gives username by splitting path based on OS
print "username: " + os.... | 10 | 2013-12-05T14:39:01Z | [
"python",
"portability",
"username"
] |
Is there a portable way to get the current username in Python? | 842,059 | <p>Is there a portable way to get the current user's username in Python (i.e., one that works under both Linux and Windows, at least). It would work like <code>os.getuid</code>:</p>
<pre><code>>>> os.getuid()
42
>>> os.getusername()
'slartibartfast'
</code></pre>
<p>I googled around and was surpris... | 361 | 2009-05-08T22:20:20Z | 25,875,055 | <p>For UNIX, at least, this works...</p>
<pre><code>import commands
username = commands.getoutput("echo $(whoami)")
print username
</code></pre>
<p><strong>edit:</strong>
I just looked it up and this works on Windows and UNIX:</p>
<pre><code>import commands
username = commands.getoutput("whoami")
</code></pre>
<p>O... | 5 | 2014-09-16T17:31:25Z | [
"python",
"portability",
"username"
] |
Practical GUI toolkit? | 842,075 | <p>I am thinking about cross-platform with nice programming language bindings (Java, Ruby and Python). What would be the "flattest" learning curve but yet enough powers to perform most of the standard GUI features? What would you guys/gals recommend; <a href="http://en.wikipedia.org/wiki/WxWidgets">FOX</a>, <a href="h... | 13 | 2009-05-08T22:25:43Z | 842,103 | <p>I would go with Qt. It works on all the major platforms, and it's being continually improved. You can also get started really fast.
There are bindings for Java, Ruby and Python.<br />
Plus it's free if you're writing open source programs.</p>
| 20 | 2009-05-08T22:34:06Z | [
"java",
"python",
"ruby",
"user-interface",
"cross-platform"
] |
Practical GUI toolkit? | 842,075 | <p>I am thinking about cross-platform with nice programming language bindings (Java, Ruby and Python). What would be the "flattest" learning curve but yet enough powers to perform most of the standard GUI features? What would you guys/gals recommend; <a href="http://en.wikipedia.org/wiki/WxWidgets">FOX</a>, <a href="h... | 13 | 2009-05-08T22:25:43Z | 842,109 | <p>Honestly, I've built things with Tk, wx, and Qt, and I hate them all equally. Qt's visual editor is the least obnoxious of the three I think.</p>
| 7 | 2009-05-08T22:36:20Z | [
"java",
"python",
"ruby",
"user-interface",
"cross-platform"
] |
Practical GUI toolkit? | 842,075 | <p>I am thinking about cross-platform with nice programming language bindings (Java, Ruby and Python). What would be the "flattest" learning curve but yet enough powers to perform most of the standard GUI features? What would you guys/gals recommend; <a href="http://en.wikipedia.org/wiki/WxWidgets">FOX</a>, <a href="h... | 13 | 2009-05-08T22:25:43Z | 842,127 | <p>I've not worked with Qt, so I can't judge it, but I have worked with wx and it's quite easy to work with and still quite lean. Also, wxWidgets gives you native widgets on every platform, which is a huge advantage (especially for Macs). While the others emulate the look-and-feel of the native platform, wxWidgets dire... | 1 | 2009-05-08T22:44:06Z | [
"java",
"python",
"ruby",
"user-interface",
"cross-platform"
] |
Practical GUI toolkit? | 842,075 | <p>I am thinking about cross-platform with nice programming language bindings (Java, Ruby and Python). What would be the "flattest" learning curve but yet enough powers to perform most of the standard GUI features? What would you guys/gals recommend; <a href="http://en.wikipedia.org/wiki/WxWidgets">FOX</a>, <a href="h... | 13 | 2009-05-08T22:25:43Z | 842,128 | <p>If you're considering Java, <a href="http://www.eclipse.org/swt/" rel="nofollow">SWT</a> is an excellent cross-platform GUI toolkit.</p>
| 2 | 2009-05-08T22:44:18Z | [
"java",
"python",
"ruby",
"user-interface",
"cross-platform"
] |
Practical GUI toolkit? | 842,075 | <p>I am thinking about cross-platform with nice programming language bindings (Java, Ruby and Python). What would be the "flattest" learning curve but yet enough powers to perform most of the standard GUI features? What would you guys/gals recommend; <a href="http://en.wikipedia.org/wiki/WxWidgets">FOX</a>, <a href="h... | 13 | 2009-05-08T22:25:43Z | 842,138 | <p>WX all the way!
I am not a GUI expert, designer or a even a "GUI guy", but recently I needed to write a front end for a product config tool (actually it's a collection of tools, but we wanted a single interface to access and run them all).<br />
The tools are all written in Python so naturally I turned to Python fo... | 4 | 2009-05-08T22:46:36Z | [
"java",
"python",
"ruby",
"user-interface",
"cross-platform"
] |
Practical GUI toolkit? | 842,075 | <p>I am thinking about cross-platform with nice programming language bindings (Java, Ruby and Python). What would be the "flattest" learning curve but yet enough powers to perform most of the standard GUI features? What would you guys/gals recommend; <a href="http://en.wikipedia.org/wiki/WxWidgets">FOX</a>, <a href="h... | 13 | 2009-05-08T22:25:43Z | 842,175 | <p>Tk is still a very viable solution. The learning curve depends a lot on you. Many folks, like myself, can or have learned all the fundamentals of Tcl and Tk in about a day. There are those that still fight the syntax after years of use. It all depends on how good you are at "unlearning" things you've learned with tr... | 3 | 2009-05-08T22:57:48Z | [
"java",
"python",
"ruby",
"user-interface",
"cross-platform"
] |
Practical GUI toolkit? | 842,075 | <p>I am thinking about cross-platform with nice programming language bindings (Java, Ruby and Python). What would be the "flattest" learning curve but yet enough powers to perform most of the standard GUI features? What would you guys/gals recommend; <a href="http://en.wikipedia.org/wiki/WxWidgets">FOX</a>, <a href="h... | 13 | 2009-05-08T22:25:43Z | 842,188 | <p>If Java is your preferred language, consider <a href="http://en.wikipedia.org/wiki/Groovy_%28programming_language%29" rel="nofollow">Groovy</a>. It is a really nice dynamic language that sits on top of Java, and has some really nice features (SwingBuilder) with respect to writing GUIs. If it wasn't for the fact I'm ... | 1 | 2009-05-08T23:01:36Z | [
"java",
"python",
"ruby",
"user-interface",
"cross-platform"
] |
Practical GUI toolkit? | 842,075 | <p>I am thinking about cross-platform with nice programming language bindings (Java, Ruby and Python). What would be the "flattest" learning curve but yet enough powers to perform most of the standard GUI features? What would you guys/gals recommend; <a href="http://en.wikipedia.org/wiki/WxWidgets">FOX</a>, <a href="h... | 13 | 2009-05-08T22:25:43Z | 842,826 | <p>I recommend Gtk. It is a nice, cross-platform, good-looking toolkit. It is designed with language bindings in mind and allows create nice language bindings (pygtk, ruby/gtk2, java-gnome, gtk# and more). Gtk+ is quite easy to learn.</p>
| 1 | 2009-05-09T06:40:54Z | [
"java",
"python",
"ruby",
"user-interface",
"cross-platform"
] |
Practical GUI toolkit? | 842,075 | <p>I am thinking about cross-platform with nice programming language bindings (Java, Ruby and Python). What would be the "flattest" learning curve but yet enough powers to perform most of the standard GUI features? What would you guys/gals recommend; <a href="http://en.wikipedia.org/wiki/WxWidgets">FOX</a>, <a href="h... | 13 | 2009-05-08T22:25:43Z | 843,548 | <p>I strongly recommend the <a href="http://rads.stackoverflow.com/amzn/click/0132354187" rel="nofollow">Rapid GUI Programming python development</a> book. <a href="http://www.qtrac.eu/pyqtbook.html" rel="nofollow">Author's Page</a>.</p>
<p>I recall that Elsevier has released a Python-GUI book book but the link and th... | 2 | 2009-05-09T16:06:15Z | [
"java",
"python",
"ruby",
"user-interface",
"cross-platform"
] |
Practical GUI toolkit? | 842,075 | <p>I am thinking about cross-platform with nice programming language bindings (Java, Ruby and Python). What would be the "flattest" learning curve but yet enough powers to perform most of the standard GUI features? What would you guys/gals recommend; <a href="http://en.wikipedia.org/wiki/WxWidgets">FOX</a>, <a href="h... | 13 | 2009-05-08T22:25:43Z | 1,156,964 | <p>I just want to mention that Qt is much much more than just a GUI toolkit. You get so much more with it, all nicely integrated into the framework, that it would be well worth using it if you are considering crossplatform development. The only issue is that if you want to use it via its Python binding PyQt, you'll eit... | 0 | 2009-07-21T02:05:10Z | [
"java",
"python",
"ruby",
"user-interface",
"cross-platform"
] |
Practical GUI toolkit? | 842,075 | <p>I am thinking about cross-platform with nice programming language bindings (Java, Ruby and Python). What would be the "flattest" learning curve but yet enough powers to perform most of the standard GUI features? What would you guys/gals recommend; <a href="http://en.wikipedia.org/wiki/WxWidgets">FOX</a>, <a href="h... | 13 | 2009-05-08T22:25:43Z | 9,626,255 | <p>Gtk is a great cross-platform toolkit. Also, the bindings for ruby are all available in a rubygem, so its very easy to install. Gtk is used for many programs like nautilus, and has many, many capibilities. The tradeoff is that Gtk does so much, that its a bit complex. </p>
<p>When I write a gui, I refuse to hand... | 0 | 2012-03-08T22:48:16Z | [
"java",
"python",
"ruby",
"user-interface",
"cross-platform"
] |
Piping Batch File output to a Python script | 842,120 | <p>I'm trying to write a python script (in windows) that runs a batch file and will take the command line output of that batch file as input. The batch file runs processes that I don't have access to and gives output based on whether those processes are successful. I'd like to take those messages from the batch file an... | 3 | 2009-05-08T22:41:21Z | 842,139 | <p>Try subprocess.Popen(). It allows you to redirect stdout and stderr to files.</p>
| 1 | 2009-05-08T22:47:00Z | [
"python",
"windows",
"scripting",
"batch-file",
"io"
] |
Piping Batch File output to a Python script | 842,120 | <p>I'm trying to write a python script (in windows) that runs a batch file and will take the command line output of that batch file as input. The batch file runs processes that I don't have access to and gives output based on whether those processes are successful. I'd like to take those messages from the batch file an... | 3 | 2009-05-08T22:41:21Z | 842,327 | <p>Here is a sample python script that runs test.bat and displays the output:</p>
<pre><code>import os
fh = os.popen("test.bat")
output = fh.read()
print "This is the output of test.bat:", output
fh.close()
</code></pre>
<p>Source of test.bat:</p>
<pre><code>@echo off
echo "This is test.bat"
</code></pre>
| 2 | 2009-05-09T00:01:12Z | [
"python",
"windows",
"scripting",
"batch-file",
"io"
] |
Piping Batch File output to a Python script | 842,120 | <p>I'm trying to write a python script (in windows) that runs a batch file and will take the command line output of that batch file as input. The batch file runs processes that I don't have access to and gives output based on whether those processes are successful. I'd like to take those messages from the batch file an... | 3 | 2009-05-08T22:41:21Z | 842,372 | <pre><code>import subprocess
output= subprocess.Popen(
("c:\\bin\\batch.bat", "an_argument", "another_argument"),
stdout=subprocess.PIPE).stdout
for line in output:
# do your work here
output.close()
</code></pre>
<p>Note that it's preferable to start your batch file with "<code>@echo off</code>".</p>
| 7 | 2009-05-09T00:24:23Z | [
"python",
"windows",
"scripting",
"batch-file",
"io"
] |
Which is more accurate, x**.5 or math.sqrt(x)? | 842,245 | <p>I recently discovered that <code>x**.5</code> and <code>math.sqrt(x)</code> do not always produce the same result in Python:</p>
<pre><code>Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)]
on win32
>>> 8885558**.5 - math.sqrt(8885558)
-4.5474735088646412e-13
</code></pre>
<p>Che... | 17 | 2009-05-08T23:33:00Z | 842,258 | <p>Both the pow function and the math.sqrt() function can calculate results that are more accurate than what the default float type can store. I think the errors you're seeing is a result of the limitations of floating point math rather than inaccuracies of the functions. Also, since when is a difference of ~10^(-13) a... | 10 | 2009-05-08T23:37:57Z | [
"python",
"floating-point"
] |
Which is more accurate, x**.5 or math.sqrt(x)? | 842,245 | <p>I recently discovered that <code>x**.5</code> and <code>math.sqrt(x)</code> do not always produce the same result in Python:</p>
<pre><code>Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)]
on win32
>>> 8885558**.5 - math.sqrt(8885558)
-4.5474735088646412e-13
</code></pre>
<p>Che... | 17 | 2009-05-08T23:33:00Z | 842,272 | <p>Any time you are given a choice between two functions which are built into a language, the more specific function will almost always be equal to or better than the generic one (since if it was worse, the coders would've just implemented it in terms of the generic function). Sqrt is more specific than generic expone... | 4 | 2009-05-08T23:44:21Z | [
"python",
"floating-point"
] |
Which is more accurate, x**.5 or math.sqrt(x)? | 842,245 | <p>I recently discovered that <code>x**.5</code> and <code>math.sqrt(x)</code> do not always produce the same result in Python:</p>
<pre><code>Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)]
on win32
>>> 8885558**.5 - math.sqrt(8885558)
-4.5474735088646412e-13
</code></pre>
<p>Che... | 17 | 2009-05-08T23:33:00Z | 842,275 | <p>I don't get the same behavior. Perhaps the error is platform specific?
On amd64 I get this:</p>
<pre>
Python 2.5.2 (r252:60911, Mar 10 2008, 15:14:55)
[GCC 3.3.5 (propolice)] on openbsd4
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.sqrt(8885558) - (8885558**.5)
0... | 1 | 2009-05-08T23:46:46Z | [
"python",
"floating-point"
] |
Which is more accurate, x**.5 or math.sqrt(x)? | 842,245 | <p>I recently discovered that <code>x**.5</code> and <code>math.sqrt(x)</code> do not always produce the same result in Python:</p>
<pre><code>Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)]
on win32
>>> 8885558**.5 - math.sqrt(8885558)
-4.5474735088646412e-13
</code></pre>
<p>Che... | 17 | 2009-05-08T23:33:00Z | 842,290 | <p>This has to be some kind of platform-specific thing because I get different results:</p>
<pre><code>Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
>>> 8885558**.5 - math.sqrt(8885558)
0.0
</code></pre>
<p>What version of python are you using and what OS?</p... | 3 | 2009-05-08T23:49:19Z | [
"python",
"floating-point"
] |
Which is more accurate, x**.5 or math.sqrt(x)? | 842,245 | <p>I recently discovered that <code>x**.5</code> and <code>math.sqrt(x)</code> do not always produce the same result in Python:</p>
<pre><code>Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)]
on win32
>>> 8885558**.5 - math.sqrt(8885558)
-4.5474735088646412e-13
</code></pre>
<p>Che... | 17 | 2009-05-08T23:33:00Z | 842,358 | <p>Neither one is more accurate, they both diverge from the actual answer in equal parts:</p>
<pre><code>>>> (8885558**0.5)**2
8885557.9999999981
>>> sqrt(8885558)**2
8885558.0000000019
>>> 2**1023.99999999999
1.7976931348498497e+308
>>> (sqrt(2**1023.99999999999))**2
1.7976931348... | 22 | 2009-05-09T00:17:04Z | [
"python",
"floating-point"
] |
Which is more accurate, x**.5 or math.sqrt(x)? | 842,245 | <p>I recently discovered that <code>x**.5</code> and <code>math.sqrt(x)</code> do not always produce the same result in Python:</p>
<pre><code>Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)]
on win32
>>> 8885558**.5 - math.sqrt(8885558)
-4.5474735088646412e-13
</code></pre>
<p>Che... | 17 | 2009-05-08T23:33:00Z | 842,365 | <p>Use <code>decimal</code> to find more precise square roots:</p>
<pre><code>>>> import decimal
>>> decimal.getcontext().prec = 60
>>> decimal.Decimal(8885558).sqrt()
Decimal("2980.86531061032678789963529280900544861029083861907705317042")
</code></pre>
| 5 | 2009-05-09T00:20:14Z | [
"python",
"floating-point"
] |
Which is more accurate, x**.5 or math.sqrt(x)? | 842,245 | <p>I recently discovered that <code>x**.5</code> and <code>math.sqrt(x)</code> do not always produce the same result in Python:</p>
<pre><code>Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)]
on win32
>>> 8885558**.5 - math.sqrt(8885558)
-4.5474735088646412e-13
</code></pre>
<p>Che... | 17 | 2009-05-08T23:33:00Z | 842,424 | <p>I got the same issue with you on Win XP Python 2.5.1, while I don't on 32-bit Gentoo Python 2.5.4. It's a matter of C library implementation.</p>
<p>Now, on Win, <code>math.sqrt(8885558)**2</code> gives <code>8885558.0000000019</code>, while <code>(8885558**.5)**2</code> gives <code>8885557.9999999981</code>, which... | 3 | 2009-05-09T00:56:23Z | [
"python",
"floating-point"
] |
Which is more accurate, x**.5 or math.sqrt(x)? | 842,245 | <p>I recently discovered that <code>x**.5</code> and <code>math.sqrt(x)</code> do not always produce the same result in Python:</p>
<pre><code>Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)]
on win32
>>> 8885558**.5 - math.sqrt(8885558)
-4.5474735088646412e-13
</code></pre>
<p>Che... | 17 | 2009-05-08T23:33:00Z | 842,885 | <p>In theory math.sqrt should have a higher precision then math.pow. See Newton's method to compute square roots [0]. However the limitation in the number of decimal digits of the python float (or the C double) will probably mask the difference.</p>
<p>[0] <a href="http://en.wikipedia.org/wiki/Integer_square_root" rel... | 1 | 2009-05-09T07:48:40Z | [
"python",
"floating-point"
] |
Which is more accurate, x**.5 or math.sqrt(x)? | 842,245 | <p>I recently discovered that <code>x**.5</code> and <code>math.sqrt(x)</code> do not always produce the same result in Python:</p>
<pre><code>Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)]
on win32
>>> 8885558**.5 - math.sqrt(8885558)
-4.5474735088646412e-13
</code></pre>
<p>Che... | 17 | 2009-05-08T23:33:00Z | 18,970,294 | <p>I performed the same test and got the same results, 10103 differences out of 10000000. This was using Python 2.7 in Windows.</p>
<p>The difference is one of rounding. I believe when the two results differ, it is only one <a href="http://en.wikipedia.org/wiki/Unit_in_the_last_place" rel="nofollow">ULP</a> which is t... | 0 | 2013-09-23T23:01:38Z | [
"python",
"floating-point"
] |
How to prevent a block of code from being interrupted by KeyboardInterrupt in Python? | 842,557 | <p>I'm writing a program that caches some results via the pickle module. What happens at the moment is that if I hit ctrl-c at while the <code>dump</code> operation is occurring, <code>dump</code> gets interrupted and the resulting file is corrupted (i.e. only partially written, so it cannot be <code>load</code>ed agai... | 29 | 2009-05-09T02:47:10Z | 842,567 | <p>Put the function in a thread, and wait for the thread to finish.</p>
<p>Python threads cannot be interrupted except with a special C api.</p>
<pre><code>import time
from threading import Thread
def noInterrupt():
for i in xrange(4):
print i
time.sleep(1)
a = Thread(target=noInterrupt)
a.start... | 22 | 2009-05-09T02:57:23Z | [
"python"
] |
How to prevent a block of code from being interrupted by KeyboardInterrupt in Python? | 842,557 | <p>I'm writing a program that caches some results via the pickle module. What happens at the moment is that if I hit ctrl-c at while the <code>dump</code> operation is occurring, <code>dump</code> gets interrupted and the resulting file is corrupted (i.e. only partially written, so it cannot be <code>load</code>ed agai... | 29 | 2009-05-09T02:47:10Z | 842,807 | <p>Use the <a href="http://docs.python.org/library/signal.html">signal</a> module to disable SIGINT for the duration of the process:</p>
<pre><code>s = signal.signal(signal.SIGINT, signal.SIG_IGN)
do_important_stuff()
signal.signal(signal.SIGINT, s)
</code></pre>
| 17 | 2009-05-09T06:26:34Z | [
"python"
] |
How to prevent a block of code from being interrupted by KeyboardInterrupt in Python? | 842,557 | <p>I'm writing a program that caches some results via the pickle module. What happens at the moment is that if I hit ctrl-c at while the <code>dump</code> operation is occurring, <code>dump</code> gets interrupted and the resulting file is corrupted (i.e. only partially written, so it cannot be <code>load</code>ed agai... | 29 | 2009-05-09T02:47:10Z | 843,169 | <p>In my opinion using threads for this is an overkill. You can make sure the file is being saved correctly by simply doing it in a loop until a successful write was done:</p>
<pre><code>def saveToFile(obj, filename):
file = open(filename, 'w')
cPickle.dump(obj, file)
file.close()
return True
done = F... | 6 | 2009-05-09T11:49:51Z | [
"python"
] |
How to prevent a block of code from being interrupted by KeyboardInterrupt in Python? | 842,557 | <p>I'm writing a program that caches some results via the pickle module. What happens at the moment is that if I hit ctrl-c at while the <code>dump</code> operation is occurring, <code>dump</code> gets interrupted and the resulting file is corrupted (i.e. only partially written, so it cannot be <code>load</code>ed agai... | 29 | 2009-05-09T02:47:10Z | 21,919,644 | <p>The following is a context manager that attaches a signal handler for <code>SIGINT</code>. If the context manager's signal handler is called, the signal is delayed by only passing the signal to the original handler when the context manager exits. </p>
<pre><code>import signal
import logging
class DelayedKeyboardIn... | 30 | 2014-02-20T21:09:02Z | [
"python"
] |
What are some good ways to set a path in a Multi-OS supported Python script | 842,570 | <p>When writing a Python script that can be executed in different operating system environments (Windows/*nix), what are some good ways to set a path? In the example below I would like to have the logfiles stored in the logs folder under the current directory. Is this an acceptable approach (I'm rather new to Python) o... | 5 | 2009-05-09T03:00:43Z | 842,577 | <p>Definitely have a look at <code>os.path</code>. It contains many of the "safe" cross-OS path manipulation functions you need. For example, I've always done this in the scenario you're outlining:</p>
<pre><code>os.path.join(os.path.abspath(os.path.dirname(__file__)), 'logs')
</code></pre>
<p>Also note that if you... | 8 | 2009-05-09T03:06:00Z | [
"python"
] |
What are some good ways to set a path in a Multi-OS supported Python script | 842,570 | <p>When writing a Python script that can be executed in different operating system environments (Windows/*nix), what are some good ways to set a path? In the example below I would like to have the logfiles stored in the logs folder under the current directory. Is this an acceptable approach (I'm rather new to Python) o... | 5 | 2009-05-09T03:00:43Z | 842,600 | <p>First, always use os.path for path manipulation.</p>
<p>More importantly, all paths should be provided in configuration files.</p>
<p>For logging, use the <a href="http://docs.python.org/library/logging.html#logging.fileConfig" rel="nofollow">fileConfig</a> function.</p>
<p>For everything else, be sure to have a ... | 2 | 2009-05-09T03:33:23Z | [
"python"
] |
find in files using ruby or python | 842,598 | <p>A popular text editor has the following "find in files" feature that opens in a dialog box:</p>
<pre><code> Look For: __searchtext__
File Filter: *.txt; *.htm
Start From: c:/docs/2009
Report: [ ] Filenames [ ]FileCount only
Method: [ ] Regex [ ]Plain Text
</code></pre>
<p>In fa... | 4 | 2009-05-09T03:29:51Z | 842,646 | <p>I know you said you don't feel like writing it yourself, but for what it's worth, it would be very easy using <code>os.walk</code> - you could do something like this:</p>
<pre><code>results = []
if regex_search:
p = re.compile(__searchtext__)
for dir, subdirs, subfiles in os.walk('c:/docs/2009'):
for name i... | 5 | 2009-05-09T04:23:14Z | [
"python",
"ruby",
"search",
"file",
"grep"
] |
find in files using ruby or python | 842,598 | <p>A popular text editor has the following "find in files" feature that opens in a dialog box:</p>
<pre><code> Look For: __searchtext__
File Filter: *.txt; *.htm
Start From: c:/docs/2009
Report: [ ] Filenames [ ]FileCount only
Method: [ ] Regex [ ]Plain Text
</code></pre>
<p>In fa... | 4 | 2009-05-09T03:29:51Z | 842,816 | <p>Grepper is a Ruby gem by David A. Black for doing exactly that:</p>
<pre><code>g = Grepper.new
g.files = %w{ one.txt two.txt three.txt }
g.options = %w{ B2 } # two lines of before-context
g.pattern = /__search_string__/
g.run
g.results.each do |file, result|
result.matches.each do |lineno, before, line, after|... | 3 | 2009-05-09T06:33:25Z | [
"python",
"ruby",
"search",
"file",
"grep"
] |
how to use list of python objects whose representation is unicode | 842,696 | <p>I have a object which contains unicode data and I want to use that in its representaion
e.g.</p>
<pre><code># -*- coding: utf-8 -*-
class A(object):
def __unicode__(self):
return u"©au"
def __repr__(self):
return unicode(self).encode("utf-8")
__str__ = __repr__
a = A()
s1 = u"%s... | 4 | 2009-05-09T04:51:29Z | 842,701 | <pre><code># -*- coding: utf-8 -*-
class A(object):
def __unicode__(self):
return u"©au"
def __repr__(self):
return unicode(self).encode('ascii', 'replace')
__str__ = __repr__
a = A()
>>> u"%s" % a
u'\xa9au'
>>> u"%s" % [a]
u'[?au]'
</code></pre>
| 0 | 2009-05-09T04:54:18Z | [
"python",
"unicode"
] |
how to use list of python objects whose representation is unicode | 842,696 | <p>I have a object which contains unicode data and I want to use that in its representaion
e.g.</p>
<pre><code># -*- coding: utf-8 -*-
class A(object):
def __unicode__(self):
return u"©au"
def __repr__(self):
return unicode(self).encode("utf-8")
__str__ = __repr__
a = A()
s1 = u"%s... | 4 | 2009-05-09T04:51:29Z | 842,729 | <p><strong>repr</strong> and <strong>str</strong> are both supposed to return str objects, at least up to Python 2.6.x. You're getting the decode error because repr() is trying to convert your result into a str, and it's failing.</p>
<p>I believe this has changed in Python 3.x.</p>
| 0 | 2009-05-09T05:05:23Z | [
"python",
"unicode"
] |
how to use list of python objects whose representation is unicode | 842,696 | <p>I have a object which contains unicode data and I want to use that in its representaion
e.g.</p>
<pre><code># -*- coding: utf-8 -*-
class A(object):
def __unicode__(self):
return u"©au"
def __repr__(self):
return unicode(self).encode("utf-8")
__str__ = __repr__
a = A()
s1 = u"%s... | 4 | 2009-05-09T04:51:29Z | 842,804 | <p>Try:</p>
<pre><code>s2 = u"%s"%[unicode(a)]
</code></pre>
<p>Your main problem is that you are doing more conversions than you expect. Lets consider the following:</p>
<pre><code>s2 = u"%s"%[a] # gives unicode decode error
</code></pre>
<p>From <a href="http://docs.python.org/library/stdtypes.html#string-formatt... | 3 | 2009-05-09T06:17:06Z | [
"python",
"unicode"
] |
how to use list of python objects whose representation is unicode | 842,696 | <p>I have a object which contains unicode data and I want to use that in its representaion
e.g.</p>
<pre><code># -*- coding: utf-8 -*-
class A(object):
def __unicode__(self):
return u"©au"
def __repr__(self):
return unicode(self).encode("utf-8")
__str__ = __repr__
a = A()
s1 = u"%s... | 4 | 2009-05-09T04:51:29Z | 842,975 | <p>If you want to use a list of <code>unicode()</code>able objects to create a unicode string, try something like:</p>
<pre><code>u''.join([unicode(v) for v in [a,a]])
</code></pre>
| 1 | 2009-05-09T08:43:17Z | [
"python",
"unicode"
] |
how to use list of python objects whose representation is unicode | 842,696 | <p>I have a object which contains unicode data and I want to use that in its representaion
e.g.</p>
<pre><code># -*- coding: utf-8 -*-
class A(object):
def __unicode__(self):
return u"©au"
def __repr__(self):
return unicode(self).encode("utf-8")
__str__ = __repr__
a = A()
s1 = u"%s... | 4 | 2009-05-09T04:51:29Z | 843,046 | <p><code>s1 = u"%s"%a # works</code></p>
<p>This works, because when dealing with 'a' it is using its unicode representation (i.e. the <strong>unicode</strong> method),</p>
<p>when however you wrap it in a list such as '[a]' ... when you try to put that list in the string, what is being called is the unicode([a]) (wh... | 4 | 2009-05-09T09:52:02Z | [
"python",
"unicode"
] |
how to use list of python objects whose representation is unicode | 842,696 | <p>I have a object which contains unicode data and I want to use that in its representaion
e.g.</p>
<pre><code># -*- coding: utf-8 -*-
class A(object):
def __unicode__(self):
return u"©au"
def __repr__(self):
return unicode(self).encode("utf-8")
__str__ = __repr__
a = A()
s1 = u"%s... | 4 | 2009-05-09T04:51:29Z | 846,989 | <p>First of all, ask yourself what you're trying to achieve. If all you want is a round-trippable representation of the list, you should simply do the following:</p>
<pre><code>class A(object):
def __unicode__(self):
return u"©au"
def __repr__(self):
return repr(unicode(self))
__str__ = __... | 2 | 2009-05-11T06:49:41Z | [
"python",
"unicode"
] |
how to use list of python objects whose representation is unicode | 842,696 | <p>I have a object which contains unicode data and I want to use that in its representaion
e.g.</p>
<pre><code># -*- coding: utf-8 -*-
class A(object):
def __unicode__(self):
return u"©au"
def __repr__(self):
return unicode(self).encode("utf-8")
__str__ = __repr__
a = A()
s1 = u"%s... | 4 | 2009-05-09T04:51:29Z | 847,072 | <p>Since this question involves a lot of confusing unicode stuff, I thought I'd offer an analysis of what was going on here.</p>
<p>It all comes down to the implementation of <code>__unicode__</code> and <code>__repr__</code> of the builtin <code>list</code> class. Basically, it is equivalent to:</p>
<pre><code>class... | 1 | 2009-05-11T07:28:10Z | [
"python",
"unicode"
] |
Using Sql Server with Django in production | 842,831 | <p>Has anybody got recent experience with deploying a Django application with an SQL Server database back end? Our workplace is heavily invested in SQL Server and will not support Django if there isn't a sufficiently developed back end for it.</p>
<p>I'm aware of mssql.django-pyodbc and django-mssql as unofficially su... | 32 | 2009-05-09T06:45:30Z | 843,476 | <p>Haven't used it in production yet, but my initial experiences with django-mssql have been pretty solid. All you need are the Python Win32 extensions and to get the sqlserver_ado module onto your Python path. From there, you just use <code>sql_server.pyodbc</code> as your <code>DATABASE_ENGINE</code>. So far I haven'... | 1 | 2009-05-09T15:12:55Z | [
"python",
"sql-server",
"django",
"pyodbc"
] |
Using Sql Server with Django in production | 842,831 | <p>Has anybody got recent experience with deploying a Django application with an SQL Server database back end? Our workplace is heavily invested in SQL Server and will not support Django if there isn't a sufficiently developed back end for it.</p>
<p>I'm aware of mssql.django-pyodbc and django-mssql as unofficially su... | 32 | 2009-05-09T06:45:30Z | 843,500 | <p>We are using django-mssql in production at our company. We too had an existing system using mssql. For me personally it was the best design decision I have ever made because my productivity increased dramatically now that I can use django . </p>
<p>I submitted a patch but when I started using django-mssql and did ... | 4 | 2009-05-09T15:32:45Z | [
"python",
"sql-server",
"django",
"pyodbc"
] |
Using Sql Server with Django in production | 842,831 | <p>Has anybody got recent experience with deploying a Django application with an SQL Server database back end? Our workplace is heavily invested in SQL Server and will not support Django if there isn't a sufficiently developed back end for it.</p>
<p>I'm aware of mssql.django-pyodbc and django-mssql as unofficially su... | 32 | 2009-05-09T06:45:30Z | 843,517 | <p>As has been stated, django-pyodbc is a good way to go. PyODBC is probably the most mature SQL Server library for Python there is. </p>
<p>The only thing you may have problems with is that pyodbc doesn't support stored procedures very well (you can call them, but you have no way to get results from them). You <em... | 17 | 2009-05-09T15:47:54Z | [
"python",
"sql-server",
"django",
"pyodbc"
] |
Using Sql Server with Django in production | 842,831 | <p>Has anybody got recent experience with deploying a Django application with an SQL Server database back end? Our workplace is heavily invested in SQL Server and will not support Django if there isn't a sufficiently developed back end for it.</p>
<p>I'm aware of mssql.django-pyodbc and django-mssql as unofficially su... | 32 | 2009-05-09T06:45:30Z | 10,954,946 | <p>I have seen so many people get the following error after installing <code>django_mssql</code> on Windows:</p>
<pre>
django.core.exceptions.ImproperlyConfigured: 'sqlserver_ado' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql_psyco... | 4 | 2012-06-08T19:26:50Z | [
"python",
"sql-server",
"django",
"pyodbc"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.