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 |
|---|---|---|---|---|---|---|---|---|---|
Simple recursive descent in PyParsing | 1,345,039 | <p>I've tried taking <a href="http://stackoverflow.com/questions/634432/need-help-on-making-the-recursive-parser-using-pyparsing/634725#634725">this code</a> and converting it to something for a project I'm working on for programming language processing, but I'm running into an issue with a simplified version:</p>
<pr... | 17 | 2009-08-28T04:38:13Z | 1,350,314 | <p>Wow, I guess pyparsing is really on the map! Thanks Alex and John for stepping in on this question. You are both on the mark with your responses. But let me add a comment or two:</p>
<ol>
<li><p>If we suppress the opening and closing parenthesis symbols, and group the parenthesized expression using Group, pypars... | 21 | 2009-08-29T03:02:04Z | [
"python",
"pyparsing",
"recursive-descent"
] |
Simple recursive descent in PyParsing | 1,345,039 | <p>I've tried taking <a href="http://stackoverflow.com/questions/634432/need-help-on-making-the-recursive-parser-using-pyparsing/634725#634725">this code</a> and converting it to something for a project I'm working on for programming language processing, but I'm running into an issue with a simplified version:</p>
<pr... | 17 | 2009-08-28T04:38:13Z | 21,996,158 | <p>Use <code>operatorPrecedence</code> to build expressions, for example as in the example at <a href="http://pyparsing.wikispaces.com/file/view/simpleArith.py/30268305/simpleArith.py" rel="nofollow">http://pyparsing.wikispaces.com/file/view/simpleArith.py/30268305/simpleArith.py</a>. It'll build the correct expression... | 0 | 2014-02-24T18:38:33Z | [
"python",
"pyparsing",
"recursive-descent"
] |
How to set timeout detection on a RabbitMQ server? | 1,345,239 | <p>I am trying out <a href="http://www.rabbitmq.com/">RabbitMQ</a> with <a href="http://barryp.org/software/py-amqplib/">this</a> python binding.</p>
<p>One thing I noticed is that if I kill a consumer uncleanly (emulating a crashed program), the server will think that this consumer is still there for a long time. The... | 16 | 2009-08-28T05:55:14Z | 1,378,968 | <p>Please provide a few more specifics regarding the components you've declared. Usually (and independent of the the client implementation) a queue with the properties</p>
<ul>
<li>exclusive and</li>
<li>auto-delete</li>
</ul>
<p>should get removed as soon as the connection between the declaring client and the broker... | 2 | 2009-09-04T12:37:25Z | [
"python",
"message-queue",
"rabbitmq",
"amqp"
] |
How to set timeout detection on a RabbitMQ server? | 1,345,239 | <p>I am trying out <a href="http://www.rabbitmq.com/">RabbitMQ</a> with <a href="http://barryp.org/software/py-amqplib/">this</a> python binding.</p>
<p>One thing I noticed is that if I kill a consumer uncleanly (emulating a crashed program), the server will think that this consumer is still there for a long time. The... | 16 | 2009-08-28T05:55:14Z | 1,384,438 | <p>RabbitMQ doesn't have a timeout on acknowledgements from the client that a message has been processed: see <a href="http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/2009-March/003158.html">this post</a> (the whole thread might be of interest). Some salient points from the post:</p>
<blockquote>
<p>The AMQP ac... | 5 | 2009-09-05T22:46:53Z | [
"python",
"message-queue",
"rabbitmq",
"amqp"
] |
How to set timeout detection on a RabbitMQ server? | 1,345,239 | <p>I am trying out <a href="http://www.rabbitmq.com/">RabbitMQ</a> with <a href="http://barryp.org/software/py-amqplib/">this</a> python binding.</p>
<p>One thing I noticed is that if I kill a consumer uncleanly (emulating a crashed program), the server will think that this consumer is still there for a long time. The... | 16 | 2009-08-28T05:55:14Z | 1,385,416 | <p>I don't see <code>amqp_consumer.py</code> or <code>amqp_producer.py</code> in the tarball, so reproducing the fault is tricky.</p>
<p>RabbitMQ terminates connections, releasing their unacknowledged messages for redelivery to other clients, whenever it is told by the operating system that a socket has closed. Your s... | 11 | 2009-09-06T11:14:32Z | [
"python",
"message-queue",
"rabbitmq",
"amqp"
] |
How can I convert a list of strings into numeric values? | 1,345,287 | <p>How can I convert a list of strings (each of which represents a number, i.e. <code>[â1â, â2â, â3â]</code>) into numeric values.</p>
| 0 | 2009-08-28T06:11:04Z | 1,345,291 | <blockquote>
<p><a href="http://docs.python.org/library/functions.html#map" rel="nofollow">map</a>(<a href="http://docs.python.org/library/functions.html#int" rel="nofollow">int</a>, ["1", "2", "3"]) </p>
</blockquote>
<p>gives</p>
<pre><code>[1, 2, 3]
</code></pre>
| 16 | 2009-08-28T06:13:32Z | [
"python"
] |
How can I convert a list of strings into numeric values? | 1,345,287 | <p>How can I convert a list of strings (each of which represents a number, i.e. <code>[â1â, â2â, â3â]</code>) into numeric values.</p>
| 0 | 2009-08-28T06:11:04Z | 1,345,294 | <p>Try this method:</p>
<pre><code>>>> int('5')
5
</code></pre>
| 2 | 2009-08-28T06:14:26Z | [
"python"
] |
How can I convert a list of strings into numeric values? | 1,345,287 | <p>How can I convert a list of strings (each of which represents a number, i.e. <code>[â1â, â2â, â3â]</code>) into numeric values.</p>
| 0 | 2009-08-28T06:11:04Z | 1,345,298 | <p>Like this:</p>
<pre><code>map(int, ['1', '2', '3'])
</code></pre>
| 2 | 2009-08-28T06:15:23Z | [
"python"
] |
How can I convert a list of strings into numeric values? | 1,345,287 | <p>How can I convert a list of strings (each of which represents a number, i.e. <code>[â1â, â2â, â3â]</code>) into numeric values.</p>
| 0 | 2009-08-28T06:11:04Z | 1,345,299 | <p>As Long as the strings are of the form '1' rather than 'one' then you can use the int() function. </p>
<p>Some sample code would be</p>
<pre><code>strList = ['1','2','3']
numList = [int(x) for x in strList]
</code></pre>
<p>Or without the list comprehension</p>
<pre><code>strList = ['1','2','3']
numList = []
fo... | 5 | 2009-08-28T06:15:31Z | [
"python"
] |
How can I convert a list of strings into numeric values? | 1,345,287 | <p>How can I convert a list of strings (each of which represents a number, i.e. <code>[â1â, â2â, â3â]</code>) into numeric values.</p>
| 0 | 2009-08-28T06:11:04Z | 1,345,303 | <p>Use <a href="http://docs.python.org/library/functions.html#int"><code>int()</code></a> and a <a href="http://docs.python.org/tutorial/datastructures.html">list comprehensions</a>: </p>
<pre><code>>>> i = ['1', '2', '3']
>>> [int(k) for k in i]
[1, 2, 3]
</code></pre>
| 10 | 2009-08-28T06:16:47Z | [
"python"
] |
How can I convert a list of strings into numeric values? | 1,345,287 | <p>How can I convert a list of strings (each of which represents a number, i.e. <code>[â1â, â2â, â3â]</code>) into numeric values.</p>
| 0 | 2009-08-28T06:11:04Z | 8,378,198 | <pre><code>a=['1','2','3']
map(lambda x: int(x),a)
> [1, 2, 3]
</code></pre>
| 0 | 2011-12-04T20:00:59Z | [
"python"
] |
How to efficiently determine if webpage comes from a website | 1,345,341 | <p>I have some unknown webpages and I want to determine which websites they come from. I have example webpages from each website and I assume each website has a distinctive template.
I do not need complete certainty, and don't want to use too much resources matching each webpage. So crawling each website for the webpag... | 1 | 2009-08-28T06:31:49Z | 1,345,621 | <p>A quick and dirty way you can try is to split html source in html tags, then compare the resultant collections of strings. You should end up with collection of tags and content, say:</p>
<pre><code>item[n] ="<p>"
item[n+2] ="This is some content"
item[n+2] ="</p>"
</code></pre>
<p>I think a regex can d... | 0 | 2009-08-28T08:02:54Z | [
"python",
"dom",
"website",
"webpage"
] |
How to efficiently determine if webpage comes from a website | 1,345,341 | <p>I have some unknown webpages and I want to determine which websites they come from. I have example webpages from each website and I assume each website has a distinctive template.
I do not need complete certainty, and don't want to use too much resources matching each webpage. So crawling each website for the webpag... | 1 | 2009-08-28T06:31:49Z | 1,346,017 | <p>You could do this via Bayes classification. Feed a few pages from each site into the classifier first, then future pages can be tested against them to see how closely they match.</p>
<p>Bayes classifier library available here: <a href="http://www.divmod.org/trac/wiki/DivmodReverend" rel="nofollow">reverend</a> (LGP... | 4 | 2009-08-28T09:50:36Z | [
"python",
"dom",
"website",
"webpage"
] |
command line arg parsing through introspection | 1,345,448 | <p>I'm developing a management script that does a fairly large amount of work via a plethora of command-line options. The first few iterations of the script have used optparse to collect user input and then just run down the page, testing the value of each option in the appropriate order, and doing the action if necess... | 4 | 2009-08-28T06:58:04Z | 1,346,134 | <p>Don't waste time on "introspection". </p>
<p>Each "Command" or "Option" is an object with two sets of method functions or attributes.</p>
<ol>
<li><p>Provide setup information to optparse.</p></li>
<li><p>Actually do the work.</p></li>
</ol>
<p>Here's the superclass for all commands</p>
<pre><code>class Command... | 3 | 2009-08-28T10:19:58Z | [
"python",
"command-line",
"parsing"
] |
command line arg parsing through introspection | 1,345,448 | <p>I'm developing a management script that does a fairly large amount of work via a plethora of command-line options. The first few iterations of the script have used optparse to collect user input and then just run down the page, testing the value of each option in the appropriate order, and doing the action if necess... | 4 | 2009-08-28T06:58:04Z | 1,346,756 | <p>The WSGI library werkzeug provides <strong><a href="http://werkzeug.pocoo.org/documentation/dev/script.html" rel="nofollow">Management Script Utilities</a></strong> which may do what you want, or at least give you a hint how to do the introspection yourself.</p>
<pre><code>from werkzeug import script
# actions go ... | 0 | 2009-08-28T12:37:48Z | [
"python",
"command-line",
"parsing"
] |
How to quickly (easy to script) preview 3D vectors / lines? | 1,345,485 | <p>I am busy reading 3D building models from a tool and thus generating a bunch of <code>Line(p1, p2)</code> objects, each consisting of two <code>Point(x, y, z)</code> objects. I would like to display these things in a simple 3D viewer, kind of like SVG (which, as I understand, only supports 2D).</p>
<p>The reading i... | 2 | 2009-08-28T07:08:40Z | 1,345,557 | <p>I'm not a 3D-programming expert but there is a simple trick you can do.<br>
If you <em>imagine</em> that the <code>z</code> axis is vertical to your screen then you can project a 3D point <code>(x, y, z)</code> like this: <code>(zoom_factor*(x/z), zoom_factor*(y/z))</code></p>
| 1 | 2009-08-28T07:35:26Z | [
".net",
"python",
"3d",
"ironpython"
] |
How to quickly (easy to script) preview 3D vectors / lines? | 1,345,485 | <p>I am busy reading 3D building models from a tool and thus generating a bunch of <code>Line(p1, p2)</code> objects, each consisting of two <code>Point(x, y, z)</code> objects. I would like to display these things in a simple 3D viewer, kind of like SVG (which, as I understand, only supports 2D).</p>
<p>The reading i... | 2 | 2009-08-28T07:08:40Z | 1,347,584 | <p>You might try the <a href="http://pyqwt.sourceforge.net/" rel="nofollow">PyQwt3D</a> package. If that doesn't work, here's a <a href="http://www.vrplumber.com/py3d.py" rel="nofollow">list of other python packages</a> that might be useful.</p>
| 1 | 2009-08-28T15:03:35Z | [
".net",
"python",
"3d",
"ironpython"
] |
How to quickly (easy to script) preview 3D vectors / lines? | 1,345,485 | <p>I am busy reading 3D building models from a tool and thus generating a bunch of <code>Line(p1, p2)</code> objects, each consisting of two <code>Point(x, y, z)</code> objects. I would like to display these things in a simple 3D viewer, kind of like SVG (which, as I understand, only supports 2D).</p>
<p>The reading i... | 2 | 2009-08-28T07:08:40Z | 1,362,062 | <p>For using the writing to file approach you could investigate <a href="http://en.wikipedia.org/wiki/X3D" rel="nofollow">X3D</a>, which is the successor to VRML. Also see <a href="http://en.wikipedia.org/wiki/List%5Fof%5Fvector%5Fgraphics%5Fmarkup%5Flanguages" rel="nofollow">this list of vector graphics markup languag... | 1 | 2009-09-01T11:50:17Z | [
".net",
"python",
"3d",
"ironpython"
] |
How to quickly (easy to script) preview 3D vectors / lines? | 1,345,485 | <p>I am busy reading 3D building models from a tool and thus generating a bunch of <code>Line(p1, p2)</code> objects, each consisting of two <code>Point(x, y, z)</code> objects. I would like to display these things in a simple 3D viewer, kind of like SVG (which, as I understand, only supports 2D).</p>
<p>The reading i... | 2 | 2009-08-28T07:08:40Z | 2,335,105 | <p>You could look at POV-Ray. It's a ray tracer that has its own text based scene description language. IIRC, there is a python module which will generate the scene files, if not, it wouldn't be difficult to do by hand. Displaying line segments at low resolution should render fairly quickly.</p>
<p>Check here: <a href... | 1 | 2010-02-25T15:21:24Z | [
".net",
"python",
"3d",
"ironpython"
] |
Determine if an executable (or library) is 32 -or 64-bits (on Windows) | 1,345,632 | <p>I am trying to find out if a given executable (or library) is compiled for 32-bits or 64-bits from Python. I am running Vista 64-bits and would like to determine if a certain application in a directory is compiled for 32-bits or 64-bits.</p>
<p>Is there a simple way to do this using only the standard Python librari... | 5 | 2009-08-28T08:05:38Z | 1,345,697 | <p>The Windows API for this is <a href="http://msdn.microsoft.com/en-us/library/aa364819%28VS.85%29.aspx"><code>GetBinaryType</code></a>. You can call this from Python using <a href="http://sourceforge.net/projects/pywin32/files/">pywin32</a>:</p>
<pre><code>import win32file
type=GetBinaryType("myfile.exe")
if type==w... | 17 | 2009-08-28T08:27:12Z | [
"python",
"windows",
"dll",
"64bit",
"executable"
] |
Determine if an executable (or library) is 32 -or 64-bits (on Windows) | 1,345,632 | <p>I am trying to find out if a given executable (or library) is compiled for 32-bits or 64-bits from Python. I am running Vista 64-bits and would like to determine if a certain application in a directory is compiled for 32-bits or 64-bits.</p>
<p>Is there a simple way to do this using only the standard Python librari... | 5 | 2009-08-28T08:05:38Z | 1,351,790 | <p>If you're running Python 2.5 or later on Windows, you could also use the Windows API without pywin32 by using ctypes.</p>
<pre><code>from ctypes import windll, POINTER
from ctypes.wintypes import LPWSTR, DWORD, BOOL
SCS_32BIT_BINARY = 0 # A 32-bit Windows-based application
SCS_64BIT_BINARY = 6 # A 64-bit Windows-b... | 4 | 2009-08-29T16:08:37Z | [
"python",
"windows",
"dll",
"64bit",
"executable"
] |
Determine if an executable (or library) is 32 -or 64-bits (on Windows) | 1,345,632 | <p>I am trying to find out if a given executable (or library) is compiled for 32-bits or 64-bits from Python. I am running Vista 64-bits and would like to determine if a certain application in a directory is compiled for 32-bits or 64-bits.</p>
<p>Is there a simple way to do this using only the standard Python librari... | 5 | 2009-08-28T08:05:38Z | 39,762,731 | <p>I was able to use Martin B's answer successfully in a Python 3.5 program after making this adjustment:</p>
<pre><code>s=f.read(2).decode(encoding="utf-8", errors="strict")
</code></pre>
<p>Originally it worked just fine with my program in Python 2.7, but after making other necessary changes, I discovered I was get... | 0 | 2016-09-29T06:16:46Z | [
"python",
"windows",
"dll",
"64bit",
"executable"
] |
How do I find the time difference between two datetime objects in python? | 1,345,827 | <p>How do I tell the time difference in minutes between two <code>datetime</code> objects?</p>
| 117 | 2009-08-28T09:03:15Z | 1,345,847 | <p>Just subtract one from the other. You get a <code>timedelta</code> object with the difference.</p>
<pre><code>>>> import datetime
>>> d1 = datetime.datetime.now()
>>> d2 = datetime.datetime.now() # after a 5-second or so pause
>>> d2 - d1
datetime.timedelta(0, 5, 203000)
</code><... | 15 | 2009-08-28T09:06:47Z | [
"python",
"datetime"
] |
How do I find the time difference between two datetime objects in python? | 1,345,827 | <p>How do I tell the time difference in minutes between two <code>datetime</code> objects?</p>
| 117 | 2009-08-28T09:03:15Z | 1,345,852 | <pre><code>>>> import datetime
>>> a = datetime.datetime.now()
>>> b = datetime.datetime.now()
>>> c = b - a
datetime.timedelta(0, 8, 562000)
>>> divmod(c.days * 86400 + c.seconds, 60)
(0, 8) # 0 minutes, 8 seconds
</code></pre>
| 129 | 2009-08-28T09:08:13Z | [
"python",
"datetime"
] |
How do I find the time difference between two datetime objects in python? | 1,345,827 | <p>How do I tell the time difference in minutes between two <code>datetime</code> objects?</p>
| 117 | 2009-08-28T09:03:15Z | 12,654,426 | <p>New at Python 2.7 is the <code>timedelta</code> instance method <code>.total_seconds()</code>. From the Python docs, this is equivalent to <code>(td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6</code>.</p>
<p>Reference: <a href="http://docs.python.org/2/library/datetime.html#datetime.timedelta... | 71 | 2012-09-29T16:35:40Z | [
"python",
"datetime"
] |
How do I find the time difference between two datetime objects in python? | 1,345,827 | <p>How do I tell the time difference in minutes between two <code>datetime</code> objects?</p>
| 117 | 2009-08-28T09:03:15Z | 16,755,333 | <p>This is how I get the number of hours that elapsed between two datetime.datetime objects:</p>
<pre><code>before = datetime.datetime.now()
after = datetime.datetime.now()
hours = math.floor(((after - before).seconds) / 3600)
</code></pre>
| 6 | 2013-05-26T01:11:21Z | [
"python",
"datetime"
] |
How do I find the time difference between two datetime objects in python? | 1,345,827 | <p>How do I tell the time difference in minutes between two <code>datetime</code> objects?</p>
| 117 | 2009-08-28T09:03:15Z | 22,768,924 | <p>Use divmod:</p>
<pre><code>now = int(time.time()) # epoch seconds
then = now - 90000 # some time in the past
d = divmod(now-then,86400) # days
h = divmod(d[1],3600) # hours
m = divmod(h[1],60) # minutes
s = m[1] # seconds
print '%d days, %d hours, %d minutes, %d seconds' % (d[0],h[0],m[0],s)
</code></pre>
| 8 | 2014-03-31T18:05:09Z | [
"python",
"datetime"
] |
How do I find the time difference between two datetime objects in python? | 1,345,827 | <p>How do I tell the time difference in minutes between two <code>datetime</code> objects?</p>
| 117 | 2009-08-28T09:03:15Z | 26,586,568 | <p>This is my approach using <a href="https://docs.python.org/2/library/time.html#time.mktime" rel="nofollow">mktime</a>.</p>
<pre><code>from datetime import datetime, timedelta
from time import mktime
yesterday = datetime.now() - timedelta(days=1)
today = datetime.now()
difference_in_seconds = abs(mktime(yesterday.... | 1 | 2014-10-27T11:28:24Z | [
"python",
"datetime"
] |
How do I find the time difference between two datetime objects in python? | 1,345,827 | <p>How do I tell the time difference in minutes between two <code>datetime</code> objects?</p>
| 117 | 2009-08-28T09:03:15Z | 26,586,909 | <p>If <code>a</code>, <code>b</code> are datetime objects then to find the time difference between them in Python 3:</p>
<pre><code>from datetime import timedelta
time_difference = a - b
time_difference_in_minutes = time_difference / timedelta(minutes=1)
</code></pre>
<p>On earlier Python versions:</p>
<pre><code>t... | 6 | 2014-10-27T11:49:16Z | [
"python",
"datetime"
] |
How do I find the time difference between two datetime objects in python? | 1,345,827 | <p>How do I tell the time difference in minutes between two <code>datetime</code> objects?</p>
| 117 | 2009-08-28T09:03:15Z | 32,527,383 | <p>To just find the number of days: timedelta has a 'days' attribute. You can simply query that.</p>
<pre><code>>>>from datetime import datetime, timedelta
>>>d1 = datetime(2015, 9, 12, 13, 9, 45)
>>>d2 = datetime(2015, 8, 29, 21, 10, 12)
>>>d3 = d1- d2
>>>print d3
13 days,... | 1 | 2015-09-11T15:49:20Z | [
"python",
"datetime"
] |
How do I find the time difference between two datetime objects in python? | 1,345,827 | <p>How do I tell the time difference in minutes between two <code>datetime</code> objects?</p>
| 117 | 2009-08-28T09:03:15Z | 37,492,704 | <p>Just thought it might be useful to mention formatting as well in regards to timedelta. strptime() parses a string representing a time according to a format.</p>
<pre><code>import datetime
from datetime import timedelta
datetimeFormat = '%Y/%m/%d %H:%M:%S.%f'
time1 = '2016/03/16 10:01:28.585'
time2 = '2016/03/1... | 2 | 2016-05-27T21:46:44Z | [
"python",
"datetime"
] |
What's the most Pythonic way of determining endianness? | 1,346,034 | <p>I'm trying to find the best way of working out whether the machine my code is running on is big-endian or little-endian. I have a solution that works (although I haven't tested it on a big-endian machine) but it seems a bit clunky:</p>
<pre><code>import struct
little_endian = (struct.pack('@h', 1) == struct.pack('&... | 26 | 2009-08-28T09:55:21Z | 1,346,039 | <p>The answer is in the <a href="http://docs.python.org/library/sys.html">sys module</a>:</p>
<pre><code>>>> import sys
>>> sys.byteorder
'little'
</code></pre>
<p>Of course depending on your machine it may return <code>'big'</code>. Your method should certainly work too though.</p>
| 57 | 2009-08-28T09:56:17Z | [
"python",
"endianness",
"little-endian",
"big-endian"
] |
Threads in python | 1,346,098 | <p>I am beginar in python script. I want read msaccess database records and write into XML file.
Access database table have more than 20000 records.</p>
<p>Now i am able to do but , it is taking 4 to 5 minutes. So i implement threading concept. But threading also taking more than 5 to 6 minutes. Because each thread op... | 0 | 2009-08-28T10:12:44Z | 1,346,176 | <p>As mentioned please paste your code snippet. First - threads have a synchronisation overhead which is causing multi-threads to run slower.</p>
<p>Second - the msaccess/JET database is very slow and not really suited to multi-threaded use. You might like to consider SQL Server instead - SQL Server Express is free.</... | 5 | 2009-08-28T10:30:30Z | [
"python",
"multithreading"
] |
Threads in python | 1,346,098 | <p>I am beginar in python script. I want read msaccess database records and write into XML file.
Access database table have more than 20000 records.</p>
<p>Now i am able to do but , it is taking 4 to 5 minutes. So i implement threading concept. But threading also taking more than 5 to 6 minutes. Because each thread op... | 0 | 2009-08-28T10:12:44Z | 1,349,343 | <ol>
<li><p>Undo the threading stuff.</p></li>
<li><p>Run the <a href="http://docs.python.org/library/profile.html" rel="nofollow">profiler</a> on the original unthreaded code.</p></li>
<li><p>Replace the AODB business with ordinary ODBC.</p></li>
<li><p>Run the new code through the profiler.</p></li>
<li><p>Post your ... | 0 | 2009-08-28T21:03:20Z | [
"python",
"multithreading"
] |
Py2App Can't find standard modules | 1,346,297 | <p>I've created an app using py2app, which works fine, but if I zip/unzip it, the newly unzipped version can't access standard python modules like traceback, or os. The manpage for zip claims that it preserves resource forks, and I've seen other applications packaged this way (I need to be able to put this in a .zip fi... | 2 | 2009-08-28T10:57:31Z | 1,346,359 | <p>use zip -y ... to create the file whilst preserving symlinks.</p>
| 0 | 2009-08-28T11:12:43Z | [
"python",
"osx",
"py2app"
] |
Py2App Can't find standard modules | 1,346,297 | <p>I've created an app using py2app, which works fine, but if I zip/unzip it, the newly unzipped version can't access standard python modules like traceback, or os. The manpage for zip claims that it preserves resource forks, and I've seen other applications packaged this way (I need to be able to put this in a .zip fi... | 2 | 2009-08-28T10:57:31Z | 1,349,783 | <p>You probably need to give it your full PYTHONPATH.</p>
<p>Depends on your os. Here's how to find out:</p>
<p>import os [or any other std module]
os.<strong>file</strong>()</p>
| 0 | 2009-08-28T22:55:31Z | [
"python",
"osx",
"py2app"
] |
Py2App Can't find standard modules | 1,346,297 | <p>I've created an app using py2app, which works fine, but if I zip/unzip it, the newly unzipped version can't access standard python modules like traceback, or os. The manpage for zip claims that it preserves resource forks, and I've seen other applications packaged this way (I need to be able to put this in a .zip fi... | 2 | 2009-08-28T10:57:31Z | 2,043,314 | <p>This is caused by building a <strong>semi-standalone</strong> version that contains symlinks to the natively installed files and as you say, the links are lost when zipping/unzipping unless the "<strong>-y</strong>" option is used.</p>
<p>An alternate solution is to build for <strong>standalone</strong> instead, wh... | 4 | 2010-01-11T16:50:49Z | [
"python",
"osx",
"py2app"
] |
How to find out whether computer is connected to internet? | 1,346,575 | <p>How to find out whether computer is connected to internet in python?</p>
| 9 | 2009-08-28T11:59:50Z | 1,346,598 | <p>Try</p>
<pre><code>import urllib
file = urllib.urlopen("http://stackoverflow.com/")
html = file.read()
</code></pre>
<p>and see if that works, or if it throws an exception. Even if you don't use the exact code, you should get the idea.</p>
| 7 | 2009-08-28T12:06:11Z | [
"python",
"internet-connection"
] |
How to find out whether computer is connected to internet? | 1,346,575 | <p>How to find out whether computer is connected to internet in python?</p>
| 9 | 2009-08-28T11:59:50Z | 1,346,623 | <p>If you have <a href="http://docs.python.org/library/urllib2.html#urllib2.urlopen">python2.6</a> you can set a timeout. Otherwise the connection might block for a long time.</p>
<pre><code>try:
urllib2.urlopen("http://example.com", timeout=2)
except urllib2.URLError:
# There is no connection
</code></pre>
| 16 | 2009-08-28T12:11:23Z | [
"python",
"internet-connection"
] |
JavaFX or RIA desktop app (on dvd) also available on the web? | 1,346,723 | <p>Is it possible to develop an application easily available on the web that also can be distributed on DVD (installer or started from the dvd)?</p>
<p>For the moment, we use static html (frameset!) pages (generated by xml files), with one difference: pdf's are only on the DVD version, the web version only shows a pre... | 1 | 2009-08-28T12:30:40Z | 1,347,338 | <p>I think if you design it correctly to begin with, a JavaFX app can be interchanged between web-app and desktop-app relatively easily. However, I've only done this with very simple apps (specifically, Tic-Tac-Toe!), so I'm sure there might exist some caveats that I am unaware of (thus the "design it correctly" catch-... | 0 | 2009-08-28T14:26:11Z | [
"java",
"python",
"web-applications",
"javafx",
"turbogears"
] |
JavaFX or RIA desktop app (on dvd) also available on the web? | 1,346,723 | <p>Is it possible to develop an application easily available on the web that also can be distributed on DVD (installer or started from the dvd)?</p>
<p>For the moment, we use static html (frameset!) pages (generated by xml files), with one difference: pdf's are only on the DVD version, the web version only shows a pre... | 1 | 2009-08-28T12:30:40Z | 1,357,063 | <p>Yes JavaFX or Flash applications can be used to develop applications that run in different contexts. </p>
<p>However, it's not clear from your question why these would be preferable over your current solution. </p>
<p>If the information your sharing is primarily text and you're using DVD because your audience is p... | 0 | 2009-08-31T11:45:34Z | [
"java",
"python",
"web-applications",
"javafx",
"turbogears"
] |
JavaFX or RIA desktop app (on dvd) also available on the web? | 1,346,723 | <p>Is it possible to develop an application easily available on the web that also can be distributed on DVD (installer or started from the dvd)?</p>
<p>For the moment, we use static html (frameset!) pages (generated by xml files), with one difference: pdf's are only on the DVD version, the web version only shows a pre... | 1 | 2009-08-28T12:30:40Z | 1,371,752 | <p>Yes, it is possible. If you use JavaFX you will be allowed use multiple deployments. For example, NetBeans 6.7.1 with JavaFX creates several possible deployments from one project. Then you can publish this application on web, DVD, etc. You will need to slightly customize standalone deployment for DVD to be able e.g.... | 0 | 2009-09-03T06:47:17Z | [
"java",
"python",
"web-applications",
"javafx",
"turbogears"
] |
JavaFX or RIA desktop app (on dvd) also available on the web? | 1,346,723 | <p>Is it possible to develop an application easily available on the web that also can be distributed on DVD (installer or started from the dvd)?</p>
<p>For the moment, we use static html (frameset!) pages (generated by xml files), with one difference: pdf's are only on the DVD version, the web version only shows a pre... | 1 | 2009-08-28T12:30:40Z | 1,508,000 | <p>This seems like a job for flex, however I know better little about it to give a better answer.</p>
| 0 | 2009-10-02T06:29:42Z | [
"java",
"python",
"web-applications",
"javafx",
"turbogears"
] |
Use QAction without adding to menu (or toolbar) | 1,346,964 | <p>I'm trying to develop an application with a very modular approach to commands and thought it would be nice, sind I'm using pyqt, to use QAction's to bind shortcuts to the commands.<br />
However, it seems that actions shortcuts only works when the action is visible in a menu or toolbar. Does anyone know a way to get... | 3 | 2009-08-28T13:27:47Z | 1,347,104 | <p>You need to add your action to a widget before it will be processed. From the QT documentation for QAction:</p>
<blockquote>
<p>Actions are added to widgets using
QWidget::addAction() or
QGraphicsWidget::addAction(). Note
that an action must be added to a
widget before it can be used; this is
also true ... | 5 | 2009-08-28T13:49:27Z | [
"python",
"qt",
"pyqt"
] |
creating class instances from a list | 1,346,969 | <p>Using python.....I have a list that contain names. I want to use each item in the list to create instances of a class. I can't use these items in their current condition (they're strings). Does anyone know how to do this in a loop.</p>
<pre><code>class trap(movevariables):
def __init__(self):
movevariab... | 2 | 2009-08-28T13:28:35Z | 1,347,012 | <p>you're probably looking for <a href="http://docs.python.org/3.1/library/functions.html#getattr" rel="nofollow"><code>getattr</code></a>.</p>
| 0 | 2009-08-28T13:35:58Z | [
"python"
] |
creating class instances from a list | 1,346,969 | <p>Using python.....I have a list that contain names. I want to use each item in the list to create instances of a class. I can't use these items in their current condition (they're strings). Does anyone know how to do this in a loop.</p>
<pre><code>class trap(movevariables):
def __init__(self):
movevariab... | 2 | 2009-08-28T13:28:35Z | 1,347,032 | <p>You could use a dict, like:</p>
<pre><code>classes = {"foo" : foo, "bar" : bar}
</code></pre>
<p>then you could do:</p>
<pre><code>myvar = classes[somestring]()
</code></pre>
<p>this way you'll have to initialize and keep the dict, but will have control on which classes can be created.</p>
| 2 | 2009-08-28T13:37:57Z | [
"python"
] |
creating class instances from a list | 1,346,969 | <p>Using python.....I have a list that contain names. I want to use each item in the list to create instances of a class. I can't use these items in their current condition (they're strings). Does anyone know how to do this in a loop.</p>
<pre><code>class trap(movevariables):
def __init__(self):
movevariab... | 2 | 2009-08-28T13:28:35Z | 1,347,045 | <p>The getattr approach seems right, a bit more detail:</p>
<pre><code>def forname(modname, classname):
''' Returns a class of "classname" from module "modname". '''
module = __import__(modname)
classobj = getattr(module, classname)
return classobj
</code></pre>
<p>From <a href="http://www.bensnider.c... | 2 | 2009-08-28T13:40:05Z | [
"python"
] |
creating class instances from a list | 1,346,969 | <p>Using python.....I have a list that contain names. I want to use each item in the list to create instances of a class. I can't use these items in their current condition (they're strings). Does anyone know how to do this in a loop.</p>
<pre><code>class trap(movevariables):
def __init__(self):
movevariab... | 2 | 2009-08-28T13:28:35Z | 1,347,071 | <p>If it a list of classes in a string form you can:</p>
<pre><code>classes = ['foo', 'bar']
for class in classes:
obj = eval(class)
</code></pre>
<p>and to create an instance you simply do this:</p>
<pre><code>instance = obj(arg1, arg2, arg3)
</code></pre>
| 1 | 2009-08-28T13:43:39Z | [
"python"
] |
creating class instances from a list | 1,346,969 | <p>Using python.....I have a list that contain names. I want to use each item in the list to create instances of a class. I can't use these items in their current condition (they're strings). Does anyone know how to do this in a loop.</p>
<pre><code>class trap(movevariables):
def __init__(self):
movevariab... | 2 | 2009-08-28T13:28:35Z | 1,347,576 | <p><strong>EDIT</strong></p>
<p>If you want to create several instances of the class trap, here is what to do:</p>
<pre><code>namelist=['lane1', 'lane2']
traps = dict((name, trap()) for name in namelist)
</code></pre>
<p>That will create a dictionary that maps each name to the instance.</p>
<p>Then to access each i... | 1 | 2009-08-28T15:02:16Z | [
"python"
] |
Improving Python list slicing | 1,347,085 | <p>I've wondered why extend/append methods of Python don't return a reference to result list.
To build string of all combination of list with last element, I would like to write simple:</p>
<pre><code>for i in range(l, 0, -1):
yield " ".join(src[0:i-1].append(src[-1]))
</code></pre>
<p>But I've got: <code>TypeErr... | 0 | 2009-08-28T13:45:49Z | 1,347,101 | <p>The general reasoning is that the return type in <code>None</code> to indicate the <code>list</code> is being modified in-place.</p>
| 1 | 2009-08-28T13:49:10Z | [
"python",
"list"
] |
Improving Python list slicing | 1,347,085 | <p>I've wondered why extend/append methods of Python don't return a reference to result list.
To build string of all combination of list with last element, I would like to write simple:</p>
<pre><code>for i in range(l, 0, -1):
yield " ".join(src[0:i-1].append(src[-1]))
</code></pre>
<p>But I've got: <code>TypeErr... | 0 | 2009-08-28T13:45:49Z | 1,347,117 | <pre><code>for i in range(l-1, 0, -1):
yield ' '.join(src[:i] + src[-1:])
</code></pre>
<p>will do.</p>
<p>Extend/append methods modify list in place and therefore don't return the list.</p>
| 0 | 2009-08-28T13:50:37Z | [
"python",
"list"
] |
Improving Python list slicing | 1,347,085 | <p>I've wondered why extend/append methods of Python don't return a reference to result list.
To build string of all combination of list with last element, I would like to write simple:</p>
<pre><code>for i in range(l, 0, -1):
yield " ".join(src[0:i-1].append(src[-1]))
</code></pre>
<p>But I've got: <code>TypeErr... | 0 | 2009-08-28T13:45:49Z | 1,347,128 | <p>Hm, maybe replace:</p>
<pre><code>src[0:i-1].append(src[-1])
</code></pre>
<p>with:</p>
<pre><code>src[0:i-1] + src[-1:] #note the trailing ":", we want a list not an element
</code></pre>
| 7 | 2009-08-28T13:51:20Z | [
"python",
"list"
] |
Improving Python list slicing | 1,347,085 | <p>I've wondered why extend/append methods of Python don't return a reference to result list.
To build string of all combination of list with last element, I would like to write simple:</p>
<pre><code>for i in range(l, 0, -1):
yield " ".join(src[0:i-1].append(src[-1]))
</code></pre>
<p>But I've got: <code>TypeErr... | 0 | 2009-08-28T13:45:49Z | 1,347,288 | <p>To operate on the list and then return it, you can use the <code>or</code> construction:</p>
<pre><code>def append_and_return(li, x):
"""silly example"""
return (li.append(x) or li)
</code></pre>
<p>Here it is so that <code>X or Y</code> evaluates X, if X is true, returns X, else evaluates and returns Y. X nee... | -1 | 2009-08-28T14:18:09Z | [
"python",
"list"
] |
Improving Python list slicing | 1,347,085 | <p>I've wondered why extend/append methods of Python don't return a reference to result list.
To build string of all combination of list with last element, I would like to write simple:</p>
<pre><code>for i in range(l, 0, -1):
yield " ".join(src[0:i-1].append(src[-1]))
</code></pre>
<p>But I've got: <code>TypeErr... | 0 | 2009-08-28T13:45:49Z | 1,347,857 | <p>The reason mutating methods in Python do NOT return a reference to the object they've mutated can be found in the <a href="http://en.wikipedia.org/wiki/Command-query%5Fseparation" rel="nofollow">Command-Query Separation</a> principle (CQS for short). Python does not apply CQS as thoroughly as Meyer's Eiffel language... | 8 | 2009-08-28T15:47:02Z | [
"python",
"list"
] |
Moving to Python 2.6.x | 1,347,168 | <p>My stuff is developed and running on Python 2.5.2</p>
<p>I want to move some code to 3.x, but that isn't feasible because so many of the external packages I use are not there yet. (Like numpy for instance).</p>
<p>So, I'll do the intermediate step and go to 2.6.2. </p>
<p>My question: If an external module run... | 2 | 2009-08-28T13:56:09Z | 1,347,191 | <p>Most likely they will work just fine. Some things might cause DeprecationWarnings, for example sha module, but they can be ignored safely. This is my gut feeling, of course you can hit some specific thing causing problems. Anyway, a quick look over these should tell pretty fast whether your code needs work or not:</... | 8 | 2009-08-28T14:00:20Z | [
"python",
"python-2.6"
] |
Moving to Python 2.6.x | 1,347,168 | <p>My stuff is developed and running on Python 2.5.2</p>
<p>I want to move some code to 3.x, but that isn't feasible because so many of the external packages I use are not there yet. (Like numpy for instance).</p>
<p>So, I'll do the intermediate step and go to 2.6.2. </p>
<p>My question: If an external module run... | 2 | 2009-08-28T13:56:09Z | 1,347,199 | <p>You can't assume that. However, you should be able to easily test if it works or not.</p>
<p>Also, do not bother trying to move to 3.x for another year or two. 2.6 has many of 3.0's features back-ported to it already, so the transition won't be that bad, once you do make it.</p>
| 2 | 2009-08-28T14:01:47Z | [
"python",
"python-2.6"
] |
Moving to Python 2.6.x | 1,347,168 | <p>My stuff is developed and running on Python 2.5.2</p>
<p>I want to move some code to 3.x, but that isn't feasible because so many of the external packages I use are not there yet. (Like numpy for instance).</p>
<p>So, I'll do the intermediate step and go to 2.6.2. </p>
<p>My question: If an external module run... | 2 | 2009-08-28T13:56:09Z | 1,347,458 | <p>It is probably worth reading the <a href="http://docs.python.org/whatsnew/2.6.html" rel="nofollow">What's New</a> section of the 2.6 documentation. While 2.6 is designed to be backwards compatible, there are a few changes that could catch code, particular code that is doing something odd (example: <code>hasattr()</c... | 1 | 2009-08-28T14:44:03Z | [
"python",
"python-2.6"
] |
Moving to Python 2.6.x | 1,347,168 | <p>My stuff is developed and running on Python 2.5.2</p>
<p>I want to move some code to 3.x, but that isn't feasible because so many of the external packages I use are not there yet. (Like numpy for instance).</p>
<p>So, I'll do the intermediate step and go to 2.6.2. </p>
<p>My question: If an external module run... | 2 | 2009-08-28T13:56:09Z | 1,347,750 | <p>The main issue will come with any C-coded extensions you may be using: depending on your system, but especially on Windows, such extensions, compiled for 2.5, are likely to not work at all (or at least not quietly and reliably) with 2.6. That's not particularly different from, e.g., migrating from 2.4 to 2.5 in the... | 3 | 2009-08-28T15:28:33Z | [
"python",
"python-2.6"
] |
ctype question char** | 1,347,280 | <p>I'm trying to figure out why this works after lots and lots of messing about with </p>
<p>obo.librar_version is a c function which requires char ** as the input and does a strcpy
to passed in char.</p>
<pre><code>from ctypes import *
_OBO_C_DLL = 'obo.dll'
STRING = c_char_p
OBO_VERSION = _stdcall_libraries[_OBO_C... | 1 | 2009-08-28T14:16:56Z | 1,347,415 | <p>When you cast <code>s</code> to <code>c_char_p</code> you store a new object in <code>t</code>, not a reference. So when you pass <code>t</code> to your function by reference, <code>s</code> doesn't get updated.</p>
<p><strong>UPDATE:</strong></p>
<p>You are indeed correct: </p>
<blockquote>
<p>cast takes two... | 1 | 2009-08-28T14:36:42Z | [
"python",
"ctypes"
] |
ctype question char** | 1,347,280 | <p>I'm trying to figure out why this works after lots and lots of messing about with </p>
<p>obo.librar_version is a c function which requires char ** as the input and does a strcpy
to passed in char.</p>
<pre><code>from ctypes import *
_OBO_C_DLL = 'obo.dll'
STRING = c_char_p
OBO_VERSION = _stdcall_libraries[_OBO_C... | 1 | 2009-08-28T14:16:56Z | 1,348,923 | <p>Because library_version requires a char**, they don't want you to allocate the characters (as you're doing with create_string_buffer. Instead, they just want you to pass in a reference to a pointer so they can return the address of where to find the version string.</p>
<p>So all you need to do is allocate the poin... | 0 | 2009-08-28T19:33:53Z | [
"python",
"ctypes"
] |
Python version shipping with Mac OS X Snow Leopard? | 1,347,376 | <p>I would appreciate it if somebody running the final version of Snow Leopard could post what version of Python is included with the OS (on a Terminal, just type "python --version")</p>
<p>Thanks!</p>
| 10 | 2009-08-28T14:30:28Z | 1,347,397 | <p>Python 2.6.1</p>
<p>(according to the web)</p>
<p>Really good to know :)</p>
| 3 | 2009-08-28T14:33:05Z | [
"python",
"osx",
"osx-snow-leopard"
] |
Python version shipping with Mac OS X Snow Leopard? | 1,347,376 | <p>I would appreciate it if somebody running the final version of Snow Leopard could post what version of Python is included with the OS (on a Terminal, just type "python --version")</p>
<p>Thanks!</p>
| 10 | 2009-08-28T14:30:28Z | 1,348,251 | <pre><code>bot:nasuni jesse$ python
Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
</code></pre>
<p>Probably the biggest reason I went and upgraded this morning, it's not 2.6.2, but it's... | 5 | 2009-08-28T16:54:08Z | [
"python",
"osx",
"osx-snow-leopard"
] |
Python version shipping with Mac OS X Snow Leopard? | 1,347,376 | <p>I would appreciate it if somebody running the final version of Snow Leopard could post what version of Python is included with the OS (on a Terminal, just type "python --version")</p>
<p>Thanks!</p>
| 10 | 2009-08-28T14:30:28Z | 1,350,316 | <p>It ships with both python 2.6.1 and 2.5.4.</p>
<blockquote>
<p>$ python2.5</p>
<p>Python 2.5.4 (r254:67916, Jul 7 2009, 23:51:24)</p>
<p>$ python</p>
<p>Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) </p>
</blockquote>
| 12 | 2009-08-29T03:03:07Z | [
"python",
"osx",
"osx-snow-leopard"
] |
Python version shipping with Mac OS X Snow Leopard? | 1,347,376 | <p>I would appreciate it if somebody running the final version of Snow Leopard could post what version of Python is included with the OS (on a Terminal, just type "python --version")</p>
<p>Thanks!</p>
| 10 | 2009-08-28T14:30:28Z | 1,352,207 | <p>You can get an installer for 2.6.2 from python.org, no reason to go without.</p>
| 1 | 2009-08-29T19:38:57Z | [
"python",
"osx",
"osx-snow-leopard"
] |
Python version shipping with Mac OS X Snow Leopard? | 1,347,376 | <p>I would appreciate it if somebody running the final version of Snow Leopard could post what version of Python is included with the OS (on a Terminal, just type "python --version")</p>
<p>Thanks!</p>
| 10 | 2009-08-28T14:30:28Z | 1,363,299 | <p><a href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/python.1.html" rel="nofollow">http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/python.1.html</a></p>
| 3 | 2009-09-01T16:01:35Z | [
"python",
"osx",
"osx-snow-leopard"
] |
Summing up two columns the Unix way | 1,347,457 | <h1># To fix the symptom</h1>
<p><strong>How can you sum up the following columns effectively?</strong></p>
<p><em>Column 1</em></p>
<pre><code>1
3
3
...
</code></pre>
<p><em>Column 2</em></p>
<pre><code>2323
343
232
...
</code></pre>
<p>This should give me</p>
<p><em>Expected result</em></p>
<pre><code>2324
34... | 1 | 2009-08-28T14:43:59Z | 1,347,472 | <p>Using python:</p>
<pre><code>totals = [ int(i)+int(j) for i, j in zip ( open(fname1), open(fname2) ) ]
</code></pre>
| 11 | 2009-08-28T14:46:28Z | [
"python",
"perl",
"unix",
"awk",
"brackets"
] |
Summing up two columns the Unix way | 1,347,457 | <h1># To fix the symptom</h1>
<p><strong>How can you sum up the following columns effectively?</strong></p>
<p><em>Column 1</em></p>
<pre><code>1
3
3
...
</code></pre>
<p><em>Column 2</em></p>
<pre><code>2323
343
232
...
</code></pre>
<p>This should give me</p>
<p><em>Expected result</em></p>
<pre><code>2324
34... | 1 | 2009-08-28T14:43:59Z | 1,347,520 | <p>You can avoid the intermediate steps by just using a command that do the counts and the comparison at the same time:</p>
<pre><code>find . -type f -exec perl -nle 'END { print $ARGV if $h{"{"} != $h{"}"} } $h{$_}++ for /([}{])/g' {}\;
</code></pre>
<p>This calls the Perl program once per file, the Perl program cou... | 3 | 2009-08-28T14:53:38Z | [
"python",
"perl",
"unix",
"awk",
"brackets"
] |
Summing up two columns the Unix way | 1,347,457 | <h1># To fix the symptom</h1>
<p><strong>How can you sum up the following columns effectively?</strong></p>
<p><em>Column 1</em></p>
<pre><code>1
3
3
...
</code></pre>
<p><em>Column 2</em></p>
<pre><code>2323
343
232
...
</code></pre>
<p>This should give me</p>
<p><em>Expected result</em></p>
<pre><code>2324
34... | 1 | 2009-08-28T14:43:59Z | 1,347,521 | <p>If c1 and c2 are youre files, you can do this:</p>
<pre><code>$ paste c1 c2 | awk '{print $1 + $2}'
</code></pre>
<p>Or (without AWK):</p>
<pre><code>$ paste c1 c2 | while read i j; do echo $(($i+$j)); done
</code></pre>
| 11 | 2009-08-28T14:53:43Z | [
"python",
"perl",
"unix",
"awk",
"brackets"
] |
Summing up two columns the Unix way | 1,347,457 | <h1># To fix the symptom</h1>
<p><strong>How can you sum up the following columns effectively?</strong></p>
<p><em>Column 1</em></p>
<pre><code>1
3
3
...
</code></pre>
<p><em>Column 2</em></p>
<pre><code>2323
343
232
...
</code></pre>
<p>This should give me</p>
<p><em>Expected result</em></p>
<pre><code>2324
34... | 1 | 2009-08-28T14:43:59Z | 1,347,604 | <p>In Python (or Perl, Awk, &c) you can reasonably do it in a single stand-alone "pass" -- I'm not sure what you mean by "too many curly brackets", but you can surely count curly use per file. For example (unless you have to worry about multi-GB files), the 10 files using most curly braces:</p>
<pre><code>import ... | 1 | 2009-08-28T15:06:39Z | [
"python",
"perl",
"unix",
"awk",
"brackets"
] |
Summing up two columns the Unix way | 1,347,457 | <h1># To fix the symptom</h1>
<p><strong>How can you sum up the following columns effectively?</strong></p>
<p><em>Column 1</em></p>
<pre><code>1
3
3
...
</code></pre>
<p><em>Column 2</em></p>
<pre><code>2323
343
232
...
</code></pre>
<p>This should give me</p>
<p><em>Expected result</em></p>
<pre><code>2324
34... | 1 | 2009-08-28T14:43:59Z | 1,347,751 | <p><strong>Reply to Lutz'n answer</strong></p>
<p>My problem was finally solved by this commnad</p>
<pre><code>paste -d: /tmp/1 /tmp/2 | awk -F: '{ print $1 "\t" $2 - $4 }'
</code></pre>
| 0 | 2009-08-28T15:29:00Z | [
"python",
"perl",
"unix",
"awk",
"brackets"
] |
Summing up two columns the Unix way | 1,347,457 | <h1># To fix the symptom</h1>
<p><strong>How can you sum up the following columns effectively?</strong></p>
<p><em>Column 1</em></p>
<pre><code>1
3
3
...
</code></pre>
<p><em>Column 2</em></p>
<pre><code>2323
343
232
...
</code></pre>
<p>This should give me</p>
<p><em>Expected result</em></p>
<pre><code>2324
34... | 1 | 2009-08-28T14:43:59Z | 1,353,960 | <p>your problem can be solved with just 1 awk command...</p>
<pre><code>awk '{getline i<"file1";print i+$0}' file2
</code></pre>
| 0 | 2009-08-30T14:12:44Z | [
"python",
"perl",
"unix",
"awk",
"brackets"
] |
Documenting class attribute | 1,347,566 | <p>Following sample is taken from "Dive into python" book.</p>
<pre><code>class MP3FileInfo(FileInfo):
"store ID3v1.0 MP3 tags"
tagDataMap = ...
</code></pre>
<p>This sample shows documenting the MP3FileInfo, but how can I add help to MP3FileInfo. tagDataMap</p>
| 5 | 2009-08-28T15:00:53Z | 1,347,582 | <p>Change it into a property method.</p>
| 1 | 2009-08-28T15:03:11Z | [
"python",
"class",
"attributes",
"self-documenting"
] |
Documenting class attribute | 1,347,566 | <p>Following sample is taken from "Dive into python" book.</p>
<pre><code>class MP3FileInfo(FileInfo):
"store ID3v1.0 MP3 tags"
tagDataMap = ...
</code></pre>
<p>This sample shows documenting the MP3FileInfo, but how can I add help to MP3FileInfo. tagDataMap</p>
| 5 | 2009-08-28T15:00:53Z | 1,347,591 | <p>The <a href="http://www.python.org/dev/peps/pep-0224/" rel="nofollow">PEP 224</a> on attribute docstrings was rejected (long time ago), so this is a problem for me as well, sometimes I don't know to choose a class attribute or an instance property -- the second can have a docstring.</p>
| 4 | 2009-08-28T15:04:17Z | [
"python",
"class",
"attributes",
"self-documenting"
] |
Documenting class attribute | 1,347,566 | <p>Following sample is taken from "Dive into python" book.</p>
<pre><code>class MP3FileInfo(FileInfo):
"store ID3v1.0 MP3 tags"
tagDataMap = ...
</code></pre>
<p>This sample shows documenting the MP3FileInfo, but how can I add help to MP3FileInfo. tagDataMap</p>
| 5 | 2009-08-28T15:00:53Z | 1,347,896 | <p>Do it like this:</p>
<pre><code>class MP3FileInfo(FileInfo):
"""Store ID3v1.0 MP3 tags."""
@property
def tagDataMap(self):
"""This function computes map of tags.
The amount of work necessary to compute is quite large, therefore
we memoize the result.
"""
...
<... | 0 | 2009-08-28T15:53:27Z | [
"python",
"class",
"attributes",
"self-documenting"
] |
Generate test coverage information from pyunit unittests? | 1,347,727 | <p>I have some pyunit unit tests for a simple command line programme I'm writing. Is it possible for me to generate test coverage numbers? I want to see what lines aren't being covered by my tests.</p>
| 2 | 2009-08-28T15:24:56Z | 1,347,755 | <p>I regularly use Ned Batchelder's <a href="http://nedbatchelder.com/code/modules/coverage.html">coverage.py</a> tool for exactly this purpose.</p>
| 7 | 2009-08-28T15:30:19Z | [
"python",
"unit-testing",
"testing",
"code-coverage",
"pyunit"
] |
Generate test coverage information from pyunit unittests? | 1,347,727 | <p>I have some pyunit unit tests for a simple command line programme I'm writing. Is it possible for me to generate test coverage numbers? I want to see what lines aren't being covered by my tests.</p>
| 2 | 2009-08-28T15:24:56Z | 1,347,783 | <p>If you run your tests with <a href="http://code.google.com/p/testoob/" rel="nofollow">testoob</a> you can get a coverage report with <code>--coverage</code>. Can install with easy_install. No changes to your tests necessary:</p>
<pre><code>testoob alltests.py --coverage
</code></pre>
| 1 | 2009-08-28T15:35:06Z | [
"python",
"unit-testing",
"testing",
"code-coverage",
"pyunit"
] |
"Unicode Error "unicodeescape" codec can't decode bytes... Cannot open text files in Python 3 | 1,347,791 | <p>I am using python 3.1, on a windows 7 machines. Russian is the default system language, and utf-8 is the default encoding.</p>
<p>Looking at the answer to a <a href="http://stackoverflow.com/questions/778096/problem-opening-a-text-document-unicode-error">previous question</a>, I have attempting using the "codecs" m... | 63 | 2009-08-28T15:36:39Z | 1,347,854 | <p>The problem is with the string</p>
<pre><code>"C:\Users\Eric\Desktop\beeline.txt"
</code></pre>
<p>Here, <code>\U</code> starts an eight-character Unicode escape, such as '\U00014321`. In your code, the escape is followed by the character 's', which is invalid.</p>
<p>You either need to duplicate all backslashes,... | 146 | 2009-08-28T15:46:24Z | [
"python",
"unicode",
"python-3.x"
] |
"Unicode Error "unicodeescape" codec can't decode bytes... Cannot open text files in Python 3 | 1,347,791 | <p>I am using python 3.1, on a windows 7 machines. Russian is the default system language, and utf-8 is the default encoding.</p>
<p>Looking at the answer to a <a href="http://stackoverflow.com/questions/778096/problem-opening-a-text-document-unicode-error">previous question</a>, I have attempting using the "codecs" m... | 63 | 2009-08-28T15:36:39Z | 19,255,661 | <p>I had this same error in python 3.2.</p>
<p>I have script for email sending and:</p>
<pre><code>csv.reader(open('work_dir\uslugi1.csv', newline='', encoding='utf-8'))
</code></pre>
<p>when I remove first char in file <code>uslugi1.csv</code> works fine.</p>
| 1 | 2013-10-08T18:38:37Z | [
"python",
"unicode",
"python-3.x"
] |
"Unicode Error "unicodeescape" codec can't decode bytes... Cannot open text files in Python 3 | 1,347,791 | <p>I am using python 3.1, on a windows 7 machines. Russian is the default system language, and utf-8 is the default encoding.</p>
<p>Looking at the answer to a <a href="http://stackoverflow.com/questions/778096/problem-opening-a-text-document-unicode-error">previous question</a>, I have attempting using the "codecs" m... | 63 | 2009-08-28T15:36:39Z | 28,392,894 | <p>You may use</p>
<pre><code>fileName=r"C:\Users\XYZ\ABC\def.txt"
open(fileName, encoding="utf8")
</code></pre>
| 0 | 2015-02-08T10:26:32Z | [
"python",
"unicode",
"python-3.x"
] |
"Unicode Error "unicodeescape" codec can't decode bytes... Cannot open text files in Python 3 | 1,347,791 | <p>I am using python 3.1, on a windows 7 machines. Russian is the default system language, and utf-8 is the default encoding.</p>
<p>Looking at the answer to a <a href="http://stackoverflow.com/questions/778096/problem-opening-a-text-document-unicode-error">previous question</a>, I have attempting using the "codecs" m... | 63 | 2009-08-28T15:36:39Z | 29,014,683 | <p>Typical error on Windows because the default user directory is <code>C:\user\<your_user></code>, so when you want to use this path as an string parameter into a Python function, you get a Unicode error, just because the <code>\u</code> is a Unicode escape. Any character not numeric after this produces an error... | 3 | 2015-03-12T16:04:47Z | [
"python",
"unicode",
"python-3.x"
] |
"Unicode Error "unicodeescape" codec can't decode bytes... Cannot open text files in Python 3 | 1,347,791 | <p>I am using python 3.1, on a windows 7 machines. Russian is the default system language, and utf-8 is the default encoding.</p>
<p>Looking at the answer to a <a href="http://stackoverflow.com/questions/778096/problem-opening-a-text-document-unicode-error">previous question</a>, I have attempting using the "codecs" m... | 63 | 2009-08-28T15:36:39Z | 33,494,617 | <p>Or you could replace '\' with '/' in the path.</p>
| -3 | 2015-11-03T08:38:58Z | [
"python",
"unicode",
"python-3.x"
] |
Confusion about the Python path in Python shell vs FCGI server: Why are they different? | 1,347,851 | <p>I'm trying to deploy my Django app into production on a shared server.</p>
<p>It seems I'm having problems with the Python path because I'm getting the error from the server:
No module named products.models</p>
<p>However, when I go to the root of the app and run the shell the modules load fine.</p>
<pre><code>'&... | 1 | 2009-08-28T15:45:50Z | 1,347,922 | <p>I'm somewhat confused -- if what you have in the path in the working case is:</p>
<pre><code>'/home/SecretUserAcct/django-projects/review_app'
</code></pre>
<p>i.e., including the app, why are you instead, in the second non-working case, inserting</p>
<pre><code>'/home/SecretUserAcct/django-projects/'
</code></pr... | 0 | 2009-08-28T15:56:59Z | [
"python",
"django"
] |
Confusion about the Python path in Python shell vs FCGI server: Why are they different? | 1,347,851 | <p>I'm trying to deploy my Django app into production on a shared server.</p>
<p>It seems I'm having problems with the Python path because I'm getting the error from the server:
No module named products.models</p>
<p>However, when I go to the root of the app and run the shell the modules load fine.</p>
<pre><code>'&... | 1 | 2009-08-28T15:45:50Z | 1,348,523 | <p>The Django dev server and manage.py shell put the current directory (the directory you ran manage.py from) on your python path for you. When running in production mode, you'll need to adjust your path accordingly if you have code that relies on that feature.</p>
| 0 | 2009-08-28T17:59:40Z | [
"python",
"django"
] |
How do I create a file in python without overwriting an existing file | 1,348,026 | <p>Currently I have a loop that tries to find an unused filename by adding suffixes to a filename string. Once it fails to find a file, it uses the name that failed to open a new file wit that name. Problem is this code is used in a website and there could be multiple attempts to do the same thing at the same time, s... | 20 | 2009-08-28T16:14:03Z | 1,348,057 | <p>If you are concerned about a race condition, you can <a href="http://docs.python.org/library/tempfile.html">create a temporary file</a> and then rename it.</p>
<pre><code>>>> import os
>>> import tempfile
>>> f = tempfile.NamedTemporaryFile(delete=False)
>>> f.name
'c:\\users\\hu... | 6 | 2009-08-28T16:18:51Z | [
"python",
"multithreading"
] |
How do I create a file in python without overwriting an existing file | 1,348,026 | <p>Currently I have a loop that tries to find an unused filename by adding suffixes to a filename string. Once it fails to find a file, it uses the name that failed to open a new file wit that name. Problem is this code is used in a website and there could be multiple attempts to do the same thing at the same time, s... | 20 | 2009-08-28T16:14:03Z | 1,348,073 | <p>Use <a href="https://docs.python.org/2/library/os.html#os.open"><code>os.open()</code></a> with <code>os.O_CREAT</code> and <code>os.O_EXCL</code> to create the file. That will fail if the file already exists:</p>
<pre><code>>>> fd = os.open("x", os.O_WRONLY | os.O_CREAT | os.O_EXCL)
Traceback (most recen... | 36 | 2009-08-28T16:21:33Z | [
"python",
"multithreading"
] |
How do I create a file in python without overwriting an existing file | 1,348,026 | <p>Currently I have a loop that tries to find an unused filename by adding suffixes to a filename string. Once it fails to find a file, it uses the name that failed to open a new file wit that name. Problem is this code is used in a website and there could be multiple attempts to do the same thing at the same time, s... | 20 | 2009-08-28T16:14:03Z | 1,348,441 | <p>If you have an <code>id</code> associated with each thread / process that tries to create the file, you could put that id in the suffix somewhere, thereby guaranteeing that no two processes can use the same file name.</p>
<p>This eliminates the race condition between the processes.</p>
| 0 | 2009-08-28T17:42:28Z | [
"python",
"multithreading"
] |
passing ctrl+z to pexpect | 1,348,283 | <p>How do I pass a certain key combination to a spawned/child process using the pexpect module? I'm using telnet and have to pass Ctrl+Z to a remote server.</p>
<p>Tnx</p>
| 2 | 2009-08-28T17:01:48Z | 1,348,298 | <p>use <a href="http://pexpect.sourceforge.net/pexpect.html#spawn-sendcontrol">sendcontrol()</a></p>
<p>for example:</p>
<pre><code>p = pexpect.spawn(your_cmd_here)
p.sendcontrol('z')
</code></pre>
| 7 | 2009-08-28T17:07:36Z | [
"python",
"pexpect"
] |
Gracefully-degrading pickling in Python | 1,348,315 | <p>(You may read <a href="http://stackoverflow.com/questions/1336908/python-alternatives-to-pickling-a-module">this</a> question for some background)</p>
<p>I would like to have a gracefully-degrading way to pickle objects in Python.</p>
<p>When pickling an object, let's call it the main object, sometimes the Pickler... | 6 | 2009-08-28T17:13:40Z | 1,348,822 | <p>How about the following, which is a wrapper you can use to wrap some modules (maybe any module) in something that's pickle-able. You could then subclass the Pickler object to check if the target object is a module, and if so, wrap it. Does this accomplish what you desire?</p>
<pre><code>class PickleableModuleWrap... | 0 | 2009-08-28T19:13:53Z | [
"python",
"pickle",
"graceful-degradation"
] |
Gracefully-degrading pickling in Python | 1,348,315 | <p>(You may read <a href="http://stackoverflow.com/questions/1336908/python-alternatives-to-pickling-a-module">this</a> question for some background)</p>
<p>I would like to have a gracefully-degrading way to pickle objects in Python.</p>
<p>When pickling an object, let's call it the main object, sometimes the Pickler... | 6 | 2009-08-28T17:13:40Z | 1,348,828 | <p>Hmmm, something like this?</p>
<pre><code>import sys
attribList = dir(someobject)
for attrib in attribList:
if(type(attrib) == type(sys)): #is a module
#put in a facade, either recursively list the module and do the same thing, or just put in something like str('modulename_module')
else:
#p... | 0 | 2009-08-28T19:14:32Z | [
"python",
"pickle",
"graceful-degradation"
] |
Gracefully-degrading pickling in Python | 1,348,315 | <p>(You may read <a href="http://stackoverflow.com/questions/1336908/python-alternatives-to-pickling-a-module">this</a> question for some background)</p>
<p>I would like to have a gracefully-degrading way to pickle objects in Python.</p>
<p>When pickling an object, let's call it the main object, sometimes the Pickler... | 6 | 2009-08-28T17:13:40Z | 1,349,243 | <p>You can decide and implement how any previously-unpicklable type gets pickled and unpickled: see standard library module <a href="http://docs.python.org/library/copy%5Freg.html" rel="nofollow">copy_reg</a> (renamed to <code>copyreg</code> in Python 3.*).</p>
<p>Essentially, you need to provide a function which, giv... | 3 | 2009-08-28T20:41:58Z | [
"python",
"pickle",
"graceful-degradation"
] |
SQLAlchemy session query with INSERT IGNORE | 1,348,510 | <p>I'm trying to do a bulk insert/update with SQLAlchemy. Here's a snippet:</p>
<pre><code>for od in clist:
where = and_(Offer.network_id==od['network_id'],
Offer.external_id==od['external_id'])
o = session.query(Offer).filter(where).first()
if not o:
o = Offer()
o.network_id ... | 1 | 2009-08-28T17:57:34Z | 1,351,309 | <p>The way you should be doing these things is with session.merge(). </p>
<p>You should also be using your objects relation properties. So the o above should have o.offerpayout and this a list (of objects) and your offerpayout has offerpayout.country property which is the related countries object.</p>
<p>So the abov... | 2 | 2009-08-29T12:16:57Z | [
"python",
"sqlalchemy"
] |
Different versions of msvcrt in ctypes | 1,348,547 | <p>In Windows, the <code>ctypes.cdll.msvcrt</code> object automatically exists when I import the ctypes module, and it represents the <code>msvcrt</code> Microsoft C++ runtime library <a href="http://docs.python.org/library/ctypes.html#loading-dynamic-link-libraries">according to the docs</a>.</p>
<p>However, I notice... | 5 | 2009-08-28T18:05:29Z | 1,348,903 | <p>It's not just that <code>ctypes.cdll.msvcrt</code> automatically exists, but <code>ctypes.cdll.anything</code> automatically exists, and is loaded on first access, loading <code>anything.dll</code>. So <code>ctypes.cdll.msvcrt</code> loads <code>msvcrt.dll</code>, which is a library that ships as part of Windows. It... | 10 | 2009-08-28T19:30:12Z | [
"python",
"ctypes",
"msvcrt"
] |
How do you add a custom section to the Django admin home page? | 1,348,710 | <p>In the Django admin each app you have registered with the admin gets its own section. I want to add a custom section for reporting that isn't associated with any app. How do I do that?</p>
| 2 | 2009-08-28T18:46:11Z | 1,349,413 | <p>To add a section not associated with an app, you'll have to override the admin index template. Create an admin/ directory in your project templates directory, and copy the file django/contrib/admin/templates/admin/index.html into it. Then you can add whatever markup you want to this file. The only downside (unfortun... | 1 | 2009-08-28T21:16:28Z | [
"python",
"django",
"django-admin"
] |
How do you add a custom section to the Django admin home page? | 1,348,710 | <p>In the Django admin each app you have registered with the admin gets its own section. I want to add a custom section for reporting that isn't associated with any app. How do I do that?</p>
| 2 | 2009-08-28T18:46:11Z | 1,349,768 | <p>Here you go: <a href="http://docs.djangoproject.com/en/dev/obsolete/admin-css/" rel="nofollow">http://docs.djangoproject.com/en/dev/obsolete/admin-css/</a></p>
<p>That should take care of you :P</p>
| 0 | 2009-08-28T22:51:53Z | [
"python",
"django",
"django-admin"
] |
Is there any way to add a class attribute to an input tag generated by django.models? | 1,348,723 | <p>I can't figure it out for the life of me. I don't think it's possible. Something so simple shouldn't be hard at all. Anyone?</p>
| 1 | 2009-08-28T18:48:44Z | 1,348,758 | <p>Not sure what you're referring to. Do you mean an HTML <input> tag generated by django.forms? If so, just specify a custom widget, using the attrs attribute in the constructor. See <a href="http://docs.djangoproject.com/en/dev/ref/forms/widgets/#customizing-widget-instances">docs</a>.</p>
| 5 | 2009-08-28T19:01:36Z | [
"python",
"css",
"django"
] |
Is there any way to add a class attribute to an input tag generated by django.models? | 1,348,723 | <p>I can't figure it out for the life of me. I don't think it's possible. Something so simple shouldn't be hard at all. Anyone?</p>
| 1 | 2009-08-28T18:48:44Z | 1,349,702 | <p>You just need to override the relevant field in your form class, and add your attribute to the widget. This is described clearly <a href="http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-default-field-types" rel="nofollow">in the documentation</a>.</p>
| 1 | 2009-08-28T22:33:01Z | [
"python",
"css",
"django"
] |
Is there any way to add a class attribute to an input tag generated by django.models? | 1,348,723 | <p>I can't figure it out for the life of me. I don't think it's possible. Something so simple shouldn't be hard at all. Anyone?</p>
| 1 | 2009-08-28T18:48:44Z | 1,354,181 | <p><a href="http://github.com/simonw/django-html" rel="nofollow">django-html</a> provides a templatetag which allows you to add extra attributes in the template, like so:</p>
<pre><code>{% field form.fieldname class="myclass" %}
</code></pre>
| 3 | 2009-08-30T16:07:21Z | [
"python",
"css",
"django"
] |
Is there any way to add a class attribute to an input tag generated by django.models? | 1,348,723 | <p>I can't figure it out for the life of me. I don't think it's possible. Something so simple shouldn't be hard at all. Anyone?</p>
| 1 | 2009-08-28T18:48:44Z | 17,663,424 | <p>I don't think any of these is particularly what the asker was looking for and now a few years after the question was posted this can be done much more intuitively. I think the asker wants the ModelForm field to render the input tag with a class attribute which you set in your view.</p>
<p>If so, the answer is here:... | 0 | 2013-07-15T20:35:26Z | [
"python",
"css",
"django"
] |
Show/hide a plot's legend | 1,349,202 | <p>I'm relatively new to python and am developing a pyqt GUI. I want to provide a checkbox option to show/hide a plot's legend. Is there a way to hide a legend? </p>
<p>I've tried using pyplot's '<code>_nolegend_</code>' and it appears to work on select legend entries but it creates a ValueError if applied to all entr... | 4 | 2009-08-28T20:34:48Z | 1,351,678 | <p>Here's something you can try on the command line:</p>
<pre><code>plot([3,1,4,1],label='foo')
lgd=legend()
# when you want it to be invisible:
lgd.set_visible(False)
draw()
# when you want it to be visible:
lgd.set_visible(True)
draw()
</code></pre>
<p>In a GUI program it's best to avoid pyplot and use the object... | 6 | 2009-08-29T15:15:00Z | [
"python",
"matplotlib"
] |
Matplotlib coord. sys origin to top left | 1,349,230 | <p>How can I flip the origin of a matplotlib plot to be in the upper-left corner - as opposed to the default lower-left? I'm using matplotlib.pylab.plot to produce the plot (though if there is another plotting routine that is more flexible, please let me know).</p>
<p>I'm looking for the equivalent of the matlab comm... | 8 | 2009-08-28T20:40:31Z | 1,350,146 | <p><code>axis ij</code> just makes the y-axis increase downward instead of upward, right? If so, then <a href="http://matplotlib.sourceforge.net/api/axes%5Fapi.html#matplotlib.axes.Axes.invert%5Fyaxis"><code>matplotlib.axes.invert_yaxis()</code></a> might be all you need -- but I can't test that right now.</p>
<p>If ... | 12 | 2009-08-29T01:27:29Z | [
"python",
"matplotlib",
"axes"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.