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
Is there a Python function to determine which quarter of the year a date is in?
1,406,131
<p>Sure I could write this myself, but before I go reinventing the wheel is there a function that already does this?</p>
43
2009-09-10T15:54:08Z
1,406,182
<p>Given an instance <code>x</code> of <a href="http://docs.python.org/library/datetime.html?highlight=datetime#datetime.date">datetime.date</a>, <code>(x.month-1)//3</code> will give you the quarter (0 for first quarter, 1 for second quarter, etc -- add 1 if you need to count from 1 instead;-).</p> <p><strong>Edit</s...
86
2009-09-10T16:02:18Z
[ "python", "date" ]
Is there a Python function to determine which quarter of the year a date is in?
1,406,131
<p>Sure I could write this myself, but before I go reinventing the wheel is there a function that already does this?</p>
43
2009-09-10T15:54:08Z
1,722,770
<p>hmmm so calculations can go wrong, here is a better version (just for the sake of it)</p> <pre><code>first, second, third, fourth=1,2,3,4# you can make strings if you wish :) quarterMap = {} quarterMap.update(dict(zip((1,2,3),(first,)*3))) quarterMap.update(dict(zip((4,5,6),(second,)*3))) quarterMap.update(dict(zi...
0
2009-11-12T14:55:58Z
[ "python", "date" ]
Is there a Python function to determine which quarter of the year a date is in?
1,406,131
<p>Sure I could write this myself, but before I go reinventing the wheel is there a function that already does this?</p>
43
2009-09-10T15:54:08Z
4,684,964
<p>I would suggest another arguably cleaner solution. If X is a <code>datetime.datetime.now()</code> instance, then the quarter is:</p> <pre><code>import math Q=math.ceil(X.month/3.) </code></pre> <p>ceil has to be imported from math module as it can't be accessed directly. </p>
9
2011-01-13T20:34:15Z
[ "python", "date" ]
Is there a Python function to determine which quarter of the year a date is in?
1,406,131
<p>Sure I could write this myself, but before I go reinventing the wheel is there a function that already does this?</p>
43
2009-09-10T15:54:08Z
13,766,929
<p>This is an old question but still worthy of discussion.</p> <p>Here is my solution, using the excellent <a href="http://labix.org/python-dateutil" rel="nofollow">dateutil</a> module.</p> <pre><code> from dateutil import rrule,relativedelta year = this_date.year quarters = rrule.rrule(rrule.MONTHLY, ...
1
2012-12-07T16:21:02Z
[ "python", "date" ]
Is there a Python function to determine which quarter of the year a date is in?
1,406,131
<p>Sure I could write this myself, but before I go reinventing the wheel is there a function that already does this?</p>
43
2009-09-10T15:54:08Z
28,730,328
<p>if <code>m</code> is the month number...</p> <pre><code>import math math.ceil(float(m) / 3) </code></pre>
0
2015-02-25T21:49:18Z
[ "python", "date" ]
Is there a Python function to determine which quarter of the year a date is in?
1,406,131
<p>Sure I could write this myself, but before I go reinventing the wheel is there a function that already does this?</p>
43
2009-09-10T15:54:08Z
35,691,608
<p><strong>IF</strong> you are already using <code>pandas</code>, it's quite simple.</p> <pre><code>import datetime as dt import pandas as pd quarter = pd.Timestamp(dt.date(2016, 2, 29)).quarter assert quarter == 1 </code></pre> <p>If you have a <code>date</code> column in a dataframe, you can easily create a new <c...
2
2016-02-29T03:42:54Z
[ "python", "date" ]
How do I get rid of Python Tkinter root window?
1,406,145
<p>Do you know a smart way to hide or in any other way get rid of the root window that appears, opened by <code>Tk()</code>? I would like just to use a normal dialog.</p> <p>Should I skip the dialog and put all my components in the root window? Is it possible or desirable? Or is there a smarter solution?</p>
24
2009-09-10T15:56:42Z
1,407,668
<p>I haven't tested since I don't have any Python/TKinter environment, but try this.</p> <p>In pure Tk there's a method called "wm" to manage the windows. There you can do something like "wm withdraw .mywindow" where '.mywindow' is a toplevel.</p> <p>In TkInter you should be able to do something similar to:</p> <pre...
8
2009-09-10T20:54:41Z
[ "python", "winapi", "tkinter", "tk" ]
How do I get rid of Python Tkinter root window?
1,406,145
<p>Do you know a smart way to hide or in any other way get rid of the root window that appears, opened by <code>Tk()</code>? I would like just to use a normal dialog.</p> <p>Should I skip the dialog and put all my components in the root window? Is it possible or desirable? Or is there a smarter solution?</p>
24
2009-09-10T15:56:42Z
1,407,700
<p>Probably the vast majority of of tk-based applications place all the components in the default root window. This is the most convenient way to do it since it already exists. Choosing to hide the default window and create your own is a perfectly fine thing to do, though it requires just a tiny bit of extra work. </p>...
35
2009-09-10T21:02:32Z
[ "python", "winapi", "tkinter", "tk" ]
How do I get rid of Python Tkinter root window?
1,406,145
<p>Do you know a smart way to hide or in any other way get rid of the root window that appears, opened by <code>Tk()</code>? I would like just to use a normal dialog.</p> <p>Should I skip the dialog and put all my components in the root window? Is it possible or desirable? Or is there a smarter solution?</p>
24
2009-09-10T15:56:42Z
26,932,613
<p>On OSX, iconify seems to work better:</p> <pre><code>root = Tkinter.Tk() root.iconify() </code></pre>
3
2014-11-14T14:50:19Z
[ "python", "winapi", "tkinter", "tk" ]
Emacs 23 hangs on python mode when typing string block """
1,406,213
<p>My Emacs hangs (Ubuntu 9 + Emacs 23 + Pyflakes) when I type <code>"""</code> quotes for string blocks.</p> <p>Anybody experienced the same problem? I think, it may not be an Emacs problem but some Python mode or Pyflakes which I use it for error checking.</p> <p>Anybody got around the issue? It is a really frustra...
0
2009-09-10T16:07:40Z
1,408,659
<p>are you using the external python-mode (from package python-mode) or the internal python mode ? I use pyflakes with the internal emacs python mode without any problems and this is my configuration :</p> <pre><code>(when (load "flymake" t) (defun flymake-pyflakes-init () (let* ((temp-file (flymake-init-create-tem...
1
2009-09-11T02:04:03Z
[ "python", "emacs", "pyflakes" ]
Emacs 23 hangs on python mode when typing string block """
1,406,213
<p>My Emacs hangs (Ubuntu 9 + Emacs 23 + Pyflakes) when I type <code>"""</code> quotes for string blocks.</p> <p>Anybody experienced the same problem? I think, it may not be an Emacs problem but some Python mode or Pyflakes which I use it for error checking.</p> <p>Anybody got around the issue? It is a really frustra...
0
2009-09-10T16:07:40Z
1,408,670
<p>latest pyflakes in development mode fixed this problem for me. Thanks all</p> <p><strong>sudo easy_install -U pyflakes</strong></p>
2
2009-09-11T02:08:50Z
[ "python", "emacs", "pyflakes" ]
Emacs 23 hangs on python mode when typing string block """
1,406,213
<p>My Emacs hangs (Ubuntu 9 + Emacs 23 + Pyflakes) when I type <code>"""</code> quotes for string blocks.</p> <p>Anybody experienced the same problem? I think, it may not be an Emacs problem but some Python mode or Pyflakes which I use it for error checking.</p> <p>Anybody got around the issue? It is a really frustra...
0
2009-09-10T16:07:40Z
3,036,535
<p>This is the specific pyflakes bug that causes emacs to go nonlinear: <a href="http://divmod.org/trac/ticket/2821" rel="nofollow">http://divmod.org/trac/ticket/2821</a></p>
0
2010-06-14T10:39:34Z
[ "python", "emacs", "pyflakes" ]
Why do I have this TypeError when using tkinter?
1,406,371
<p>so I upgraded to python 3.1.1 from 2.6 and i ran an old program of mine which uses tkinter.</p> <p>I get the following error message which I don't recall getting in the 2.6 version.</p> <pre><code>Exception in Tkinter callback Traceback (most recent call last): File "C:\Python31\lib\tkinter\__init__.py", line 13...
0
2009-09-10T16:36:29Z
1,406,386
<p>There were several breaking changes from Python 2.X to Python 3.X -- among them, <code>map</code>'s functionality.</p> <p>Have you run your script through <a href="http://docs.python.org/library/2to3.html" rel="nofollow">2to3</a> yet?</p>
3
2009-09-10T16:38:37Z
[ "python", "python-3.x", "tkinter", "typeerror" ]
Why do I have this TypeError when using tkinter?
1,406,371
<p>so I upgraded to python 3.1.1 from 2.6 and i ran an old program of mine which uses tkinter.</p> <p>I get the following error message which I don't recall getting in the 2.6 version.</p> <pre><code>Exception in Tkinter callback Traceback (most recent call last): File "C:\Python31\lib\tkinter\__init__.py", line 13...
0
2009-09-10T16:36:29Z
1,406,393
<pre><code>self.canvas.coords(name) </code></pre> <p>return a <code>map object</code>, and as the error states <code>map</code> object is unsubscriptable in python 3. you need to change <code>coords</code> to be a tuple or a list.</p> <p>you need to change your code to be:</p> <pre><code>temp_ids = self.canvas.find_...
2
2009-09-10T16:40:02Z
[ "python", "python-3.x", "tkinter", "typeerror" ]
Splitting a string with no line breaks into a list of lines with a maximum column count
1,406,493
<p>I have a long string (multiple paragraphs) which I need to split into a list of line strings. The determination of what makes a "line" is based on:</p> <ul> <li>The number of characters in the line is less than or equal to X (where X is a fixed number of columns per line_)</li> <li>OR, there is a newline in the or...
6
2009-09-10T16:59:30Z
1,406,514
<p>You probably want to use the textwrap function in the standard library:</p> <p><a href="http://docs.python.org/library/textwrap.html" rel="nofollow">http://docs.python.org/library/textwrap.html</a></p>
4
2009-09-10T17:03:29Z
[ "python", "text-manipulation" ]
Splitting a string with no line breaks into a list of lines with a maximum column count
1,406,493
<p>I have a long string (multiple paragraphs) which I need to split into a list of line strings. The determination of what makes a "line" is based on:</p> <ul> <li>The number of characters in the line is less than or equal to X (where X is a fixed number of columns per line_)</li> <li>OR, there is a newline in the or...
6
2009-09-10T16:59:30Z
1,406,526
<p><strong>EDIT</strong></p> <p>What you are looking for is <a href="http://docs.python.org/library/textwrap.html#module-textwrap">textwrap</a>, but that's only part of the solution not the complete one. To take newline into account you need to do this:</p> <pre><code>from textwrap import wrap '\n'.join(['\n'.join(wr...
12
2009-09-10T17:05:17Z
[ "python", "text-manipulation" ]
Non-critical unittest failures
1,406,552
<p>I'm using Python's built-in <a href="http://docs.python.org/library/unittest.html" rel="nofollow">unittest</a> module and I want to write a few tests that are not critical.</p> <p>I mean, if my program passes such tests, that's great! However, if it doesn't pass, it's not really a problem, the program will still wo...
3
2009-09-10T17:11:51Z
1,406,570
<p>As a practical matter, I'd probably use print statements to indicate failure in that case. A more correct solution is to use warnings:</p> <p><a href="http://docs.python.org/library/warnings.html" rel="nofollow">http://docs.python.org/library/warnings.html</a></p> <p>You could, however, use the logging facility to...
7
2009-09-10T17:16:11Z
[ "python", "unit-testing" ]
Non-critical unittest failures
1,406,552
<p>I'm using Python's built-in <a href="http://docs.python.org/library/unittest.html" rel="nofollow">unittest</a> module and I want to write a few tests that are not critical.</p> <p>I mean, if my program passes such tests, that's great! However, if it doesn't pass, it's not really a problem, the program will still wo...
3
2009-09-10T17:11:51Z
1,406,576
<p>Im not totally sure how unittest works, but most unit testing frameworks have something akin to categories. I suppose you could just categorize such tests, mark them to be ignored, and then run them only when your interested in them. But I know from experience that ignored tests very quickly become...just that ignor...
4
2009-09-10T17:17:30Z
[ "python", "unit-testing" ]
Non-critical unittest failures
1,406,552
<p>I'm using Python's built-in <a href="http://docs.python.org/library/unittest.html" rel="nofollow">unittest</a> module and I want to write a few tests that are not critical.</p> <p>I mean, if my program passes such tests, that's great! However, if it doesn't pass, it's not really a problem, the program will still wo...
3
2009-09-10T17:11:51Z
1,406,584
<p>You could write your test so that they count success rate. With OCR you could throw at code 1000 images and require that 95% is successful. </p> <p>If your program must work with type A then if this fails the test fails. If it's not required to work with B, what is the value of doing such a test ?</p>
-1
2009-09-10T17:19:34Z
[ "python", "unit-testing" ]
Non-critical unittest failures
1,406,552
<p>I'm using Python's built-in <a href="http://docs.python.org/library/unittest.html" rel="nofollow">unittest</a> module and I want to write a few tests that are not critical.</p> <p>I mean, if my program passes such tests, that's great! However, if it doesn't pass, it's not really a problem, the program will still wo...
3
2009-09-10T17:11:51Z
1,406,610
<p>Asserts in unit tests are binary: they will work or they will fail, there's no mid-term.</p> <p>Given that, to create those "non-critical" tests you should not use assertions when you don't want the tests to fail. You should do this carefully so you don't compromise the "usefulness" of the test.</p> <p>My advice t...
4
2009-09-10T17:27:20Z
[ "python", "unit-testing" ]
Non-critical unittest failures
1,406,552
<p>I'm using Python's built-in <a href="http://docs.python.org/library/unittest.html" rel="nofollow">unittest</a> module and I want to write a few tests that are not critical.</p> <p>I mean, if my program passes such tests, that's great! However, if it doesn't pass, it's not really a problem, the program will still wo...
3
2009-09-10T17:11:51Z
1,406,832
<p>There are some test systems that allow warnings rather than failures, but test_unit is not one of them (I don't know which ones do, offhand) unless you want to extend it (which is possible).</p> <p>You can make the tests so that they log warnings rather than fail.</p> <p>Another way to handle this is to separate o...
1
2009-09-10T18:08:33Z
[ "python", "unit-testing" ]
Non-critical unittest failures
1,406,552
<p>I'm using Python's built-in <a href="http://docs.python.org/library/unittest.html" rel="nofollow">unittest</a> module and I want to write a few tests that are not critical.</p> <p>I mean, if my program passes such tests, that's great! However, if it doesn't pass, it's not really a problem, the program will still wo...
3
2009-09-10T17:11:51Z
1,406,948
<p>Take a look at Nose : <a href="http://somethingaboutorange.com/mrl/projects/nose/0.11.1/" rel="nofollow">http://somethingaboutorange.com/mrl/projects/nose/0.11.1/</a></p> <p>There are plenty of command line options for selecting tests to run, and you can keep your existing unittest tests.</p>
0
2009-09-10T18:33:06Z
[ "python", "unit-testing" ]
Non-critical unittest failures
1,406,552
<p>I'm using Python's built-in <a href="http://docs.python.org/library/unittest.html" rel="nofollow">unittest</a> module and I want to write a few tests that are not critical.</p> <p>I mean, if my program passes such tests, that's great! However, if it doesn't pass, it's not really a problem, the program will still wo...
3
2009-09-10T17:11:51Z
1,407,485
<p>From <a href="http://docs.python.org/library/unittest.html" rel="nofollow">unittest</a> documentation which you link:</p> <blockquote> <p>Instead of unittest.main(), there are other ways to run the tests with a finer level of control, less terse output, and no requirement to be run from the command line. ...
2
2009-09-10T20:16:41Z
[ "python", "unit-testing" ]
Non-critical unittest failures
1,406,552
<p>I'm using Python's built-in <a href="http://docs.python.org/library/unittest.html" rel="nofollow">unittest</a> module and I want to write a few tests that are not critical.</p> <p>I mean, if my program passes such tests, that's great! However, if it doesn't pass, it's not really a problem, the program will still wo...
3
2009-09-10T17:11:51Z
1,407,582
<p>Another possibility is to create a "B" branch (you ARE using some sort of version control, right?) and have your unit tests for "B" in there. That way, you keep your release version's unit tests clean (Look, all dots!), but still have tests for B. If you're using a modern version control system like git or mercurial...
0
2009-09-10T20:36:18Z
[ "python", "unit-testing" ]
Non-critical unittest failures
1,406,552
<p>I'm using Python's built-in <a href="http://docs.python.org/library/unittest.html" rel="nofollow">unittest</a> module and I want to write a few tests that are not critical.</p> <p>I mean, if my program passes such tests, that's great! However, if it doesn't pass, it's not really a problem, the program will still wo...
3
2009-09-10T17:11:51Z
1,423,506
<p>Thank you for the great answers. No only one answer was really complete, so I'm writing here <a href="http://meta.stackexchange.com/questions/13413/how-do-i-combine-two-answers-to-create-the-best-answer-on-stackoverflow/13414#13414">a combination of all answers that helped me</a>. If you like this answer, please vot...
1
2009-09-14T19:42:08Z
[ "python", "unit-testing" ]
Non-critical unittest failures
1,406,552
<p>I'm using Python's built-in <a href="http://docs.python.org/library/unittest.html" rel="nofollow">unittest</a> module and I want to write a few tests that are not critical.</p> <p>I mean, if my program passes such tests, that's great! However, if it doesn't pass, it's not really a problem, the program will still wo...
3
2009-09-10T17:11:51Z
3,999,906
<p>Python 2.7 (and 3.1) added support for skipping some test methods or test cases, as well as marking some tests as <strong>expected failure</strong>.</p> <p><a href="http://docs.python.org/library/unittest.html#skipping-tests-and-expected-failures" rel="nofollow">http://docs.python.org/library/unittest.html#skipping...
0
2010-10-22T18:41:31Z
[ "python", "unit-testing" ]
How do I keep state between requests in AppEngine (Python)?
1,406,636
<p>I'm writing a simple app with AppEngine, using Python. After a successful insert by a user and redirect, I'd like to display a flash confirmation message on the next page. </p> <p>What's the best way to keep state between one request and the next? Or is this not possible because AppEngine is distributed? I guess, t...
1
2009-09-10T17:32:58Z
1,406,722
<p>No session support is included in App Engine itself, but you can add your own session support.</p> <p><a href="http://gaeutilities.appspot.com/" rel="nofollow">GAE Utilities</a> is one library made specifically for this; a more heavyweight alternative is to use django sessions through <a href="http://code.google.co...
3
2009-09-10T17:49:51Z
[ "python", "google-app-engine" ]
How do I keep state between requests in AppEngine (Python)?
1,406,636
<p>I'm writing a simple app with AppEngine, using Python. After a successful insert by a user and redirect, I'd like to display a flash confirmation message on the next page. </p> <p>What's the best way to keep state between one request and the next? Or is this not possible because AppEngine is distributed? I guess, t...
1
2009-09-10T17:32:58Z
1,406,768
<p>The ways to reliable keep state between requests are memcache, the datastore or through the user (cookies or post/get).</p> <p>You can use the runtime cache too, but this is very unreliable as you don't know if a request will end up in the same runtime or the runtime can drop it's entire cache if it feels like it.<...
3
2009-09-10T17:55:50Z
[ "python", "google-app-engine" ]
What class to use for money representation?
1,406,737
<p>What class should I use for representation of money to avoid most rounding errors?</p> <p>Should I use <code>Decimal</code>, or a simple built-in <code>number</code>?</p> <p>Is there any existing <code>Money</code> class with support for currency conversion that I could use?</p> <p>Any pitfalls that I should avoi...
10
2009-09-10T17:52:04Z
1,406,764
<p>You might be interested in <a href="http://quantlib.org/index.shtml" rel="nofollow">QuantLib</a> for working with finance. </p> <p>It has built in classes for handling currency types and claims 4 years of active development.</p>
3
2009-09-10T17:55:20Z
[ "python", "money", "rounding-error", "arbitrary-precision", "precision" ]
What class to use for money representation?
1,406,737
<p>What class should I use for representation of money to avoid most rounding errors?</p> <p>Should I use <code>Decimal</code>, or a simple built-in <code>number</code>?</p> <p>Is there any existing <code>Money</code> class with support for currency conversion that I could use?</p> <p>Any pitfalls that I should avoi...
10
2009-09-10T17:52:04Z
1,406,792
<p>You could have a look at this library: <a href="http://code.google.com/p/python-money/" rel="nofollow">python-money</a>. Since I've no experience with it I cannot comment on its usefullness.</p> <p>A 'trick' you could employ to handle currency as integers: </p> <ul> <li>Multiply by 100 / Divide by 100 (e.g. $100,2...
3
2009-09-10T17:59:53Z
[ "python", "money", "rounding-error", "arbitrary-precision", "precision" ]
What class to use for money representation?
1,406,737
<p>What class should I use for representation of money to avoid most rounding errors?</p> <p>Should I use <code>Decimal</code>, or a simple built-in <code>number</code>?</p> <p>Is there any existing <code>Money</code> class with support for currency conversion that I could use?</p> <p>Any pitfalls that I should avoi...
10
2009-09-10T17:52:04Z
1,406,800
<p>I assume that you talking about Python. <a href="http://code.google.com/p/python-money/" rel="nofollow">http://code.google.com/p/python-money/</a> "Primitives for working with money and currencies in Python" - the title is self explanatory :)</p>
3
2009-09-10T18:01:25Z
[ "python", "money", "rounding-error", "arbitrary-precision", "precision" ]
What class to use for money representation?
1,406,737
<p>What class should I use for representation of money to avoid most rounding errors?</p> <p>Should I use <code>Decimal</code>, or a simple built-in <code>number</code>?</p> <p>Is there any existing <code>Money</code> class with support for currency conversion that I could use?</p> <p>Any pitfalls that I should avoi...
10
2009-09-10T17:52:04Z
1,408,693
<p>Just use <a href="http://docs.python.org/library/decimal.html">decimal</a>.</p>
5
2009-09-11T02:20:28Z
[ "python", "money", "rounding-error", "arbitrary-precision", "precision" ]
What class to use for money representation?
1,406,737
<p>What class should I use for representation of money to avoid most rounding errors?</p> <p>Should I use <code>Decimal</code>, or a simple built-in <code>number</code>?</p> <p>Is there any existing <code>Money</code> class with support for currency conversion that I could use?</p> <p>Any pitfalls that I should avoi...
10
2009-09-10T17:52:04Z
11,620,751
<p>Never use a floating point number to represent money. Floating numbers do not represent numbers in decimal notation accurately. You would end with a nightmare of compound rounding errors, and unable to reliably convert between currencies. See <a href="http://martinfowler.com/eaaCatalog/money.html" rel="nofollow" tit...
2
2012-07-23T21:25:53Z
[ "python", "money", "rounding-error", "arbitrary-precision", "precision" ]
What class to use for money representation?
1,406,737
<p>What class should I use for representation of money to avoid most rounding errors?</p> <p>Should I use <code>Decimal</code>, or a simple built-in <code>number</code>?</p> <p>Is there any existing <code>Money</code> class with support for currency conversion that I could use?</p> <p>Any pitfalls that I should avoi...
10
2009-09-10T17:52:04Z
17,941,227
<p>Simple, light-weight, yet extensible idea:</p> <pre><code>class Money(): def __init__(self, value): # internally use Decimal or cents as long self._cents = long(0) # Now parse 'value' as needed e.g. locale-specific user-entered string, cents, Money, etc. # Decimal helps in conve...
0
2013-07-30T07:50:53Z
[ "python", "money", "rounding-error", "arbitrary-precision", "precision" ]
What class to use for money representation?
1,406,737
<p>What class should I use for representation of money to avoid most rounding errors?</p> <p>Should I use <code>Decimal</code>, or a simple built-in <code>number</code>?</p> <p>Is there any existing <code>Money</code> class with support for currency conversion that I could use?</p> <p>Any pitfalls that I should avoi...
10
2009-09-10T17:52:04Z
17,941,472
<p>It depends what you'd like to use <code>Money</code> for. </p> <p>For financial modelling of price and risk <code>double</code> (Python's <code>float</code>) is good enough because all models are inaccurate (some of them are useful though), so one doesn't get any useful extra precision by using infinite precision n...
0
2013-07-30T08:05:40Z
[ "python", "money", "rounding-error", "arbitrary-precision", "precision" ]
What is Facebook's new Tornado framework?
1,406,912
<p>Facebook just open-sourced <a href="http://developers.facebook.com/opensource.php">a framework called Tornado</a>. </p> <p>What is it? What does it help a site do?</p> <p>I believe Facebook uses a LAMP structure. Is it useful for smaller sites which are written under the LAMP stack? </p>
15
2009-09-10T18:24:25Z
1,406,930
<p>It looks like it is a web-server optimized for high-concurrency and high-scalability, but made for smaller payloads.</p> <p>It was designed to support 10,000 concurrent users well.</p> <blockquote> <p>The framework is distinct from most mainstream web server frameworks (and certainly most Python frameworks) ...
13
2009-09-10T18:27:38Z
[ "python", "facebook", "tornado" ]
What is Facebook's new Tornado framework?
1,406,912
<p>Facebook just open-sourced <a href="http://developers.facebook.com/opensource.php">a framework called Tornado</a>. </p> <p>What is it? What does it help a site do?</p> <p>I believe Facebook uses a LAMP structure. Is it useful for smaller sites which are written under the LAMP stack? </p>
15
2009-09-10T18:24:25Z
1,416,089
<p>It has <a href="http://github.com/facebook/tornado/blob/master/tornado/database.py" rel="nofollow">'database' module</a> with blocking queries. Maybe they run multiple instances of this server to minimize blocking problems and maybe it is not used for whole friendfeed, only in some parts related to real-time behavio...
0
2009-09-12T20:41:06Z
[ "python", "facebook", "tornado" ]
What is Facebook's new Tornado framework?
1,406,912
<p>Facebook just open-sourced <a href="http://developers.facebook.com/opensource.php">a framework called Tornado</a>. </p> <p>What is it? What does it help a site do?</p> <p>I believe Facebook uses a LAMP structure. Is it useful for smaller sites which are written under the LAMP stack? </p>
15
2009-09-10T18:24:25Z
3,854,210
<p>Looking for an alternative (single threaded, asynchronous, event driven high performance web server) running on the JVM? </p> <p><a href="http://www.deftserver.org" rel="nofollow">Deft web server</a></p> <p>(Disclaimer: I'm a Deft committer) </p>
1
2010-10-04T10:08:45Z
[ "python", "facebook", "tornado" ]
What is Facebook's new Tornado framework?
1,406,912
<p>Facebook just open-sourced <a href="http://developers.facebook.com/opensource.php">a framework called Tornado</a>. </p> <p>What is it? What does it help a site do?</p> <p>I believe Facebook uses a LAMP structure. Is it useful for smaller sites which are written under the LAMP stack? </p>
15
2009-09-10T18:24:25Z
6,518,959
<p>Tornado is a simple, fast python webserver and a micro web framework. Its provides the very basic framework to write a dynamic website. Its very easy to learn and extend to meet specific need of a demanding web application since it does not come in your way. The best part of using Tornado is it does not create threa...
0
2011-06-29T10:09:56Z
[ "python", "facebook", "tornado" ]
How to generate basic CRUD functionality in python given a database tables
1,407,016
<p>I want to develop a desktop application using python with basic crud operation. Is there any library in python that can generate a code for CRUD functionality and user interface given a database table.</p>
2
2009-09-10T18:45:49Z
1,407,116
<p>If it were me, I would consider borrowing django's ORM, but then again, I'm already familiar with it.</p> <p>Having said that, I like working with it, it's usable outside the framework, and it will give you mysql, postgres, or sqlite support. You could also hook up the django admin site to your models and have a we...
0
2009-09-10T19:04:38Z
[ "python", "database", "desktop", "crud" ]
How to generate basic CRUD functionality in python given a database tables
1,407,016
<p>I want to develop a desktop application using python with basic crud operation. Is there any library in python that can generate a code for CRUD functionality and user interface given a database table.</p>
2
2009-09-10T18:45:49Z
1,407,136
<p>Hopefully, this won't be the best option you end up with, but, in the tradition of using web-interfaces for desktop applications, you could always try <a href="http://www.djangoproject.com/" rel="nofollow">django</a>. I would particularLY take a look at the <a href="http://docs.djangoproject.com/en/dev/ref/django-...
3
2009-09-10T19:07:40Z
[ "python", "database", "desktop", "crud" ]
How to generate basic CRUD functionality in python given a database tables
1,407,016
<p>I want to develop a desktop application using python with basic crud operation. Is there any library in python that can generate a code for CRUD functionality and user interface given a database table.</p>
2
2009-09-10T18:45:49Z
1,408,043
<p>If you want something really small and simple, I like the <a href="http://autumn-orm.org/" rel="nofollow">Autumn</a> ORM.</p> <p>If you use the Django ORM, you can use the automatically-generated Django admin interface, which is really nice. It's basically a web-based GUI for browsing and editing records in your d...
0
2009-09-10T22:23:10Z
[ "python", "database", "desktop", "crud" ]
distutils setup.py and %post %postun
1,407,021
<p>I am newbie. I am buidling rpm package for my own app and decided to use distutils to do achieve it. I managed to create some substitue of %post by using advice from this website, which i really am thankfull for, but i am having problems with %postun. Let me describe what i have done. In setup.py i run command that ...
4
2009-09-10T18:47:46Z
1,472,692
<p>Neither distutils nor setuptools have uninstall functionality.</p> <p>At some point, the python community agreed that uninstall should be handled by the packaging system. In this case you want to use rpm, so there is probably a way inside of rpm system to remove packages, but you will not find that in distutils or ...
0
2009-09-24T16:09:08Z
[ "python", "distutils", "rpm", "specifications" ]
distutils setup.py and %post %postun
1,407,021
<p>I am newbie. I am buidling rpm package for my own app and decided to use distutils to do achieve it. I managed to create some substitue of %post by using advice from this website, which i really am thankfull for, but i am having problems with %postun. Let me describe what i have done. In setup.py i run command that ...
4
2009-09-10T18:47:46Z
1,509,052
<p>Yes, you can specify a post install script, all you need is to declare in the bdist_rpm in the options arg the file you want to use:</p> <pre><code>setup( ... options = {'bdist_rpm':{'post_install' : 'post_install', 'post_uninstall' : 'post_uninstall'}}, ...) </code></pre> <p>In the post_un...
2
2009-10-02T11:46:13Z
[ "python", "distutils", "rpm", "specifications" ]
python database / sql programming - where to start
1,407,248
<p>What is the best way to use an embedded database, say sqlite in Python:</p> <ol> <li>Should be small footprint. I'm only needing few thousands records per table. And just a handful of tables per database.</li> <li>If it's one provided by Python default installation, then great. Must be open-source, available on Wi...
7
2009-09-10T19:31:36Z
1,407,259
<p>start with Django</p> <p><a href="http://www.djangoproject.com/" rel="nofollow">http://www.djangoproject.com/</a></p> <p>ORM is the way to go here. You won't regret it. The tutorial here <a href="http://docs.djangoproject.com/en/dev/intro/tutorial01/" rel="nofollow">http://docs.djangoproject.com/en/dev/intro/tutor...
2
2009-09-10T19:33:28Z
[ "python", "database", "sqlite", "ado" ]
python database / sql programming - where to start
1,407,248
<p>What is the best way to use an embedded database, say sqlite in Python:</p> <ol> <li>Should be small footprint. I'm only needing few thousands records per table. And just a handful of tables per database.</li> <li>If it's one provided by Python default installation, then great. Must be open-source, available on Wi...
7
2009-09-10T19:31:36Z
1,407,302
<p>I started here:</p> <p><a href="http://www.devshed.com/c/a/Python/Using-SQLite-in-Python" rel="nofollow">http://www.devshed.com/c/a/Python/Using-SQLite-in-Python</a></p> <p>It's 5 (short) pages with just the essentials got me going right away.</p>
3
2009-09-10T19:41:45Z
[ "python", "database", "sqlite", "ado" ]
python database / sql programming - where to start
1,407,248
<p>What is the best way to use an embedded database, say sqlite in Python:</p> <ol> <li>Should be small footprint. I'm only needing few thousands records per table. And just a handful of tables per database.</li> <li>If it's one provided by Python default installation, then great. Must be open-source, available on Wi...
7
2009-09-10T19:31:36Z
1,407,345
<p>Django is perfect for this but the poster is not clear if he needs to actually make a compiled EXE or a web app. Django is only for web apps.</p> <p>I'm not sure where you really get "heavy" from. Django is grossly smaller in terms of lines of code than any other major web app framework.</p>
0
2009-09-10T19:48:41Z
[ "python", "database", "sqlite", "ado" ]
python database / sql programming - where to start
1,407,248
<p>What is the best way to use an embedded database, say sqlite in Python:</p> <ol> <li>Should be small footprint. I'm only needing few thousands records per table. And just a handful of tables per database.</li> <li>If it's one provided by Python default installation, then great. Must be open-source, available on Wi...
7
2009-09-10T19:31:36Z
1,407,569
<p>I highly recommend the use of a good ORM. When you can work with Python objects to manage your database rows, life is so much easier.</p> <p>I am a fan of the ORM in Django. But that was already recommended and you said that is too heavyweight.</p> <p>This leaves me with exactly one ORM to recommend: <a href="ht...
6
2009-09-10T20:34:07Z
[ "python", "database", "sqlite", "ado" ]
python database / sql programming - where to start
1,407,248
<p>What is the best way to use an embedded database, say sqlite in Python:</p> <ol> <li>Should be small footprint. I'm only needing few thousands records per table. And just a handful of tables per database.</li> <li>If it's one provided by Python default installation, then great. Must be open-source, available on Wi...
7
2009-09-10T19:31:36Z
1,407,607
<p>What you're looking for is <a href="http://www.sqlalchemy.org/" rel="nofollow">SQLAlchemy</a>, which is fast becoming the de facto standard Python data access layer. To make your first experiences with SQLAlchemy even easier, check out <a href="http://elixir.ematia.de/trac/wiki" rel="nofollow">Elixir</a>, which is ...
3
2009-09-10T20:42:08Z
[ "python", "database", "sqlite", "ado" ]
python database / sql programming - where to start
1,407,248
<p>What is the best way to use an embedded database, say sqlite in Python:</p> <ol> <li>Should be small footprint. I'm only needing few thousands records per table. And just a handful of tables per database.</li> <li>If it's one provided by Python default installation, then great. Must be open-source, available on Wi...
7
2009-09-10T19:31:36Z
1,408,573
<p>Another option to add to the other good suggestions: <a href="http://elixir.ematia.de/trac/wiki" rel="nofollow">Elixir</a>. It provides a simplified declarative layer on top of <code>SQLAlchemy</code>, so it should be easier to dive into, but it also allows you to call upon the full power of <code>SQLAlchemy</code>...
0
2009-09-11T01:28:44Z
[ "python", "database", "sqlite", "ado" ]
python database / sql programming - where to start
1,407,248
<p>What is the best way to use an embedded database, say sqlite in Python:</p> <ol> <li>Should be small footprint. I'm only needing few thousands records per table. And just a handful of tables per database.</li> <li>If it's one provided by Python default installation, then great. Must be open-source, available on Wi...
7
2009-09-10T19:31:36Z
1,409,333
<p>This is an aggregate of answers, in no particular order:</p> <p>Everybody is recommending an ORM layer. Which makes perfect sense, if you really need a database. Well, that was sort of requested in the title :-)</p> <ol> <li><a href="http://www.sqlalchemy.org/" rel="nofollow">SQLAlchemy</a></li> <li><a href="htt...
1
2009-09-11T06:41:53Z
[ "python", "database", "sqlite", "ado" ]
python database / sql programming - where to start
1,407,248
<p>What is the best way to use an embedded database, say sqlite in Python:</p> <ol> <li>Should be small footprint. I'm only needing few thousands records per table. And just a handful of tables per database.</li> <li>If it's one provided by Python default installation, then great. Must be open-source, available on Wi...
7
2009-09-10T19:31:36Z
1,802,137
<p>There's an easy-to-use Python module that meets all the stated objectives: </p> <p><a href="http://yserial.sourceforge.net/" rel="nofollow">http://yserial.sourceforge.net/</a></p> <p>Serialization + persistance: in a few lines of code, compress and annotate Python objects into SQLite; then later retrieve them chro...
0
2009-11-26T07:47:27Z
[ "python", "database", "sqlite", "ado" ]
python database / sql programming - where to start
1,407,248
<p>What is the best way to use an embedded database, say sqlite in Python:</p> <ol> <li>Should be small footprint. I'm only needing few thousands records per table. And just a handful of tables per database.</li> <li>If it's one provided by Python default installation, then great. Must be open-source, available on Wi...
7
2009-09-10T19:31:36Z
19,759,324
<p>If you don't want to use an ORM, you can give a try to <a href="https://pypi.python.org/pypi/python-sql" rel="nofollow">python-sql</a> to create your SQL queries.</p>
0
2013-11-03T23:06:37Z
[ "python", "database", "sqlite", "ado" ]
Why does the Python gettext module require a compilation step (.po -> .mo)?
1,407,364
<p>I don't see that the compilation step is adding any value.</p>
0
2009-09-10T19:52:00Z
1,407,416
<p>I think that the compilation is .po -> .mo</p> <blockquote> <p>The letters PO in .po files means Portable Object, to distinguish it from .mo files, where MO stands for Machine Object.</p> <p>MO files are meant to be read by programs, and are binary in nature. A few systems already offer tools for creating an...
0
2009-09-10T20:02:00Z
[ "python", "gettext" ]
Why does the Python gettext module require a compilation step (.po -> .mo)?
1,407,364
<p>I don't see that the compilation step is adding any value.</p>
0
2009-09-10T19:52:00Z
1,408,109
<p>Reading just quickly about <code>.mo</code> files, it is clear that:</p> <ul> <li>It is a machine-readable representation</li> <li>It is a hash table</li> </ul> <p>Given gettext's function, to lookup strings by keys <em>at runtime</em>, it is reasonable for this lookup to be implemented efficiently.</p> <p>Also, ...
5
2009-09-10T22:43:41Z
[ "python", "gettext" ]
Why does the Python gettext module require a compilation step (.po -> .mo)?
1,407,364
<p>I don't see that the compilation step is adding any value.</p>
0
2009-09-10T19:52:00Z
2,021,653
<p>Because gettext module in Python follows GNU gettext standards which required to use PO files for do translations by people, and MO files for using by application in runtime. When you're using gettext module you're actually using GNUTranslations class, which name suggests it's implementation of GNU gettext.</p> <p>...
1
2010-01-07T16:02:54Z
[ "python", "gettext" ]
How do I regex match with grouping with unknown number of groups
1,407,435
<p>I want to do a regex match (in Python) on the output log of a program. The log contains some lines that look like this:</p> <pre><code>... VALUE 100 234 568 9233 119 ... VALUE 101 124 9223 4329 1559 ... </code></pre> <p>I would like to capture the list of numbers that occurs after the first incidence of the line...
13
2009-09-10T20:06:45Z
1,407,457
<p>What you're looking for is a <em>parser</em>, instead of a regular expression match. In your case, I would consider using a very simple parser, <a href="http://docs.python.org/library/stdtypes.html#str.split"><code>split()</code></a>:</p> <pre><code>s = "VALUE 100 234 568 9233 119" a = s.split() if a[0] == "VALUE":...
12
2009-09-10T20:12:21Z
[ "python", "regex" ]
How do I regex match with grouping with unknown number of groups
1,407,435
<p>I want to do a regex match (in Python) on the output log of a program. The log contains some lines that look like this:</p> <pre><code>... VALUE 100 234 568 9233 119 ... VALUE 101 124 9223 4329 1559 ... </code></pre> <p>I would like to capture the list of numbers that occurs after the first incidence of the line...
13
2009-09-10T20:06:45Z
1,407,470
<p>You could just run you're main match regex then run a secondary regex on those matches to get the numbers:</p> <pre><code>matches = Regex.Match(log) foreach (Match match in matches) { submatches = Regex2.Match(match) } </code></pre> <p>This is of course also if you don't want to write a full parser.</p>
0
2009-09-10T20:14:27Z
[ "python", "regex" ]
How do I regex match with grouping with unknown number of groups
1,407,435
<p>I want to do a regex match (in Python) on the output log of a program. The log contains some lines that look like this:</p> <pre><code>... VALUE 100 234 568 9233 119 ... VALUE 101 124 9223 4329 1559 ... </code></pre> <p>I would like to capture the list of numbers that occurs after the first incidence of the line...
13
2009-09-10T20:06:45Z
1,407,491
<pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; reg = re.compile('\d+') &gt;&gt;&gt; reg.findall('VALUE 100 234 568 9233 119') ['100', '234', '568', '9223', '119'] </code></pre> <p>That doesn't validate that the keyword 'VALUE' appears at the beginning of the string, and it doesn't validate that there is exactly one sp...
6
2009-09-10T20:17:51Z
[ "python", "regex" ]
Does python logging.handlers.RotatingFileHandler allow creation of a group writable log file?
1,407,474
<p>I'm using the standard python (2.5.2) logging module, specifically the RotatingFileHandler, on a linux system. My application supports both a command-line interface and a web-service interface. I would like to have both write to the same log file. However, when the log file gets rotated, the new file has 644 perm...
23
2009-09-10T20:14:44Z
1,407,835
<p>I resorted to scanning the logging.handlers module and was unable to see any way to specify a different file permissions mode. So, I have a solution now based on extending the RotatingFileHandler as a custom handler. It was fairly painless, once I found some nice references to creating one. The code for the custom...
14
2009-09-10T21:29:32Z
[ "python", "logging" ]
Does python logging.handlers.RotatingFileHandler allow creation of a group writable log file?
1,407,474
<p>I'm using the standard python (2.5.2) logging module, specifically the RotatingFileHandler, on a linux system. My application supports both a command-line interface and a web-service interface. I would like to have both write to the same log file. However, when the log file gets rotated, the new file has 644 perm...
23
2009-09-10T20:14:44Z
6,779,307
<p>Here is a slightly better solution. this overrides the _open method that is used. setting the umask before creating then returning it back to what it was.</p> <pre><code>class GroupWriteRotatingFileHandler(logging.handlers.RotatingFileHandler): def _open(self): prevumask=os.umask(0o002) #os....
20
2011-07-21T16:16:39Z
[ "python", "logging" ]
Does python logging.handlers.RotatingFileHandler allow creation of a group writable log file?
1,407,474
<p>I'm using the standard python (2.5.2) logging module, specifically the RotatingFileHandler, on a linux system. My application supports both a command-line interface and a web-service interface. I would like to have both write to the same log file. However, when the log file gets rotated, the new file has 644 perm...
23
2009-09-10T20:14:44Z
11,852,400
<p>James Gardner has written a handler that only rotates files, not creating or deleting them: <a href="http://packages.python.org/logrotate/index.html" rel="nofollow">http://packages.python.org/logrotate/index.html</a></p>
1
2012-08-07T19:01:29Z
[ "python", "logging" ]
Does python logging.handlers.RotatingFileHandler allow creation of a group writable log file?
1,407,474
<p>I'm using the standard python (2.5.2) logging module, specifically the RotatingFileHandler, on a linux system. My application supports both a command-line interface and a web-service interface. I would like to have both write to the same log file. However, when the log file gets rotated, the new file has 644 perm...
23
2009-09-10T20:14:44Z
37,519,766
<pre><code>$ chgrp loggroup logdir $ chmod g+w logdir $ chmod g+s logdir $ usermod -a -G loggroup myuser $ umask 0002 </code></pre>
0
2016-05-30T07:19:02Z
[ "python", "logging" ]
Python: How do I convert a NonType variable to a String?
1,407,557
<p>I have the following function: </p> <pre><code>&gt;&gt;&gt; def rule(x): ... rule = bin(x)[2:].zfill(8) ... rule = str(rule) ... print rule </code></pre> <p>I am trying to convert rule into a string, but when I run the following command, here is what I get: </p> <pre><code>&gt;&gt;&gt; type(rule(20)) ...
1
2009-09-10T20:32:16Z
1,407,572
<p>you need to do:</p> <pre><code>def rule(x): return bin(x)[2:].zfill(8) </code></pre> <p>All functions return <code>None</code> implicitly if no <code>return</code> statement was encountered during execution of the function (as it is in your case).</p>
5
2009-09-10T20:34:50Z
[ "python" ]
Python: How do I convert a NonType variable to a String?
1,407,557
<p>I have the following function: </p> <pre><code>&gt;&gt;&gt; def rule(x): ... rule = bin(x)[2:].zfill(8) ... rule = str(rule) ... print rule </code></pre> <p>I am trying to convert rule into a string, but when I run the following command, here is what I get: </p> <pre><code>&gt;&gt;&gt; type(rule(20)) ...
1
2009-09-10T20:32:16Z
1,407,583
<p>Your rule function doesn't return anything -- it only prints. So, rule(20) returns None -- the python object representing 'no value'. You can't turn that into a string, at least not in the way you are expecting.</p> <p>You need to define rule to return something, like this:</p> <pre><code>&gt;&gt;&gt; def rule(x):...
1
2009-09-10T20:36:27Z
[ "python" ]
Is there a Rake equivalent in Python?
1,407,837
<p>Rake is a software build tool written in Ruby (like ant or make), and so all its files are written in this language. Does something like this exist in Python?</p>
69
2009-09-10T21:29:57Z
1,407,850
<p><a href="http://paver.github.com/paver/">Paver</a> has a similar set of goals, though I don't really know how it compares.</p>
25
2009-09-10T21:32:26Z
[ "python", "build-automation" ]
Is there a Rake equivalent in Python?
1,407,837
<p>Rake is a software build tool written in Ruby (like ant or make), and so all its files are written in this language. Does something like this exist in Python?</p>
69
2009-09-10T21:29:57Z
1,407,853
<p>I would check out <a href="http://docs.python.org/library/distutils.html" rel="nofollow"><code>distutils</code></a>:</p> <blockquote> <p>The <code>distutils</code> package provides support for building and installing additional modules into a Python installation. The new modules may be either 100%-pure Py...
0
2009-09-10T21:32:30Z
[ "python", "build-automation" ]
Is there a Rake equivalent in Python?
1,407,837
<p>Rake is a software build tool written in Ruby (like ant or make), and so all its files are written in this language. Does something like this exist in Python?</p>
69
2009-09-10T21:29:57Z
1,407,897
<p><a href="http://code.google.com/p/waf/">Waf</a> is a Python-based framework for configuring, compiling and installing applications. It derives from the concepts of other build tools such as Scons, Autotools, CMake or Ant.</p>
5
2009-09-10T21:42:14Z
[ "python", "build-automation" ]
Is there a Rake equivalent in Python?
1,407,837
<p>Rake is a software build tool written in Ruby (like ant or make), and so all its files are written in this language. Does something like this exist in Python?</p>
69
2009-09-10T21:29:57Z
1,407,964
<p>Also check out buildout, which isn't so much a make system for software, as a make system for a deployment. </p> <p><a href="http://pypi.python.org/pypi/pysqlite/2.5.5" rel="nofollow">http://pypi.python.org/pypi/pysqlite/2.5.5</a></p> <p>So it's not a direct rake equivalent, but may be a better match for what you ...
0
2009-09-10T22:00:39Z
[ "python", "build-automation" ]
Is there a Rake equivalent in Python?
1,407,837
<p>Rake is a software build tool written in Ruby (like ant or make), and so all its files are written in this language. Does something like this exist in Python?</p>
69
2009-09-10T21:29:57Z
7,619,913
<p>There is <a href="https://github.com/JeremySkinner/Phantom" rel="nofollow">Phantom</a> in Boo (which isn't python but nearly).</p>
0
2011-10-01T11:22:38Z
[ "python", "build-automation" ]
Is there a Rake equivalent in Python?
1,407,837
<p>Rake is a software build tool written in Ruby (like ant or make), and so all its files are written in this language. Does something like this exist in Python?</p>
69
2009-09-10T21:29:57Z
8,704,821
<p>Although it is more commonly used for deployment, <a href="http://readthedocs.org/docs/fabric/en/latest/">Fabric</a> might be interesting for this use case.</p>
4
2012-01-02T20:00:58Z
[ "python", "build-automation" ]
Is there a Rake equivalent in Python?
1,407,837
<p>Rake is a software build tool written in Ruby (like ant or make), and so all its files are written in this language. Does something like this exist in Python?</p>
69
2009-09-10T21:29:57Z
12,166,213
<p>Shovel seems promising:</p> <p><a href="http://devblog.seomoz.org/2012/03/shovel-rake-for-python/">Shovel — Rake for Python</a></p> <p><a href="https://github.com/seomoz/shovel">https://github.com/seomoz/shovel</a></p>
13
2012-08-28T19:30:04Z
[ "python", "build-automation" ]
Is there a Rake equivalent in Python?
1,407,837
<p>Rake is a software build tool written in Ruby (like ant or make), and so all its files are written in this language. Does something like this exist in Python?</p>
69
2009-09-10T21:29:57Z
17,372,701
<p><a href="http://docs.pyinvoke.org/en/latest/">Invoke</a> — <a href="http://docs.fabfile.org/en/latest">Fabric</a> without the SSH dependencies.</p> <p>The <a href="http://docs.fabfile.org/en/1.6/roadmap.html">Fabric roadmap</a> discusses that <a href="http://docs.fabfile.org/en/latest">Fabric</a> 1.x will be spli...
30
2013-06-28T19:57:57Z
[ "python", "build-automation" ]
Is there a Rake equivalent in Python?
1,407,837
<p>Rake is a software build tool written in Ruby (like ant or make), and so all its files are written in this language. Does something like this exist in Python?</p>
69
2009-09-10T21:29:57Z
37,995,638
<p>There is also <a href="http://pydoit.org/" rel="nofollow">doit</a> - I came across it while looking for these things a while ago, though I didn't get very far with evaluating it.</p>
0
2016-06-23T15:16:33Z
[ "python", "build-automation" ]
Python urllib, minidom and parsing international characters
1,407,874
<p>When I try to retrieve information from Google weather API with the following URL,</p> <p><a href="http://www.google.com/ig/api?weather=Munich,Germany&amp;hl=de" rel="nofollow">http://www.google.com/ig/api?weather=Munich,Germany&amp;hl=de</a></p> <p>and then try to parse it with minidom, I get error that the docum...
0
2009-09-10T21:35:31Z
1,408,002
<p>This seems to work:</p> <pre><code>sock = urllib.urlopen(url) # There is a nicer way for this, but I don't remember right now: encoding = sock.headers['Content-type'].split('charset=')[1] data = sock.read() dom = minidom.parseString(data.decode(encoding).encode('ascii', 'xmlcharrefreplace')) </code></pre> <p>I gue...
2
2009-09-10T22:10:03Z
[ "python", "internationalization", "urllib", "minidom" ]
Python urllib, minidom and parsing international characters
1,407,874
<p>When I try to retrieve information from Google weather API with the following URL,</p> <p><a href="http://www.google.com/ig/api?weather=Munich,Germany&amp;hl=de" rel="nofollow">http://www.google.com/ig/api?weather=Munich,Germany&amp;hl=de</a></p> <p>and then try to parse it with minidom, I get error that the docum...
0
2009-09-10T21:35:31Z
1,408,052
<p>The encoding sent in the headers is iso-8859-1 according to python's urllib.urlopen (although firefox's live http headers seems to disagree with me in this case - reports utf-8). In the xml itself there is no encoding specified --> that's why xml.dom.minidom assumes it's utf-8. </p> <p>So the following should fix t...
1
2009-09-10T22:25:45Z
[ "python", "internationalization", "urllib", "minidom" ]
Create an executable process without using shell on Python 2.5 and below
1,407,992
<p>Just what the title says:</p> <ol> <li>The <code>subprocess</code> module cannot be used as this should work on 2.4 and 2.5</li> <li>Shell process should not be spawned to pass arguments.</li> </ol> <p>To explain (2), consider the following code:</p> <pre><code>&gt;&gt;&gt; x=os.system('foo arg') sh: foo: not fou...
1
2009-09-10T22:07:41Z
1,408,008
<p>You probably need to use the subprocess module which is available in Python 2.4</p> <pre><code>Popen("/home/user/foo" + " arg") &gt;&gt;&gt; Popen("foo arg", shell=False) Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "/usr/lib/python2.6/subprocess.py", line 595, in __i...
3
2009-09-10T22:11:33Z
[ "python", "process", "fork", "subprocess", "popen" ]
Create an executable process without using shell on Python 2.5 and below
1,407,992
<p>Just what the title says:</p> <ol> <li>The <code>subprocess</code> module cannot be used as this should work on 2.4 and 2.5</li> <li>Shell process should not be spawned to pass arguments.</li> </ol> <p>To explain (2), consider the following code:</p> <pre><code>&gt;&gt;&gt; x=os.system('foo arg') sh: foo: not fou...
1
2009-09-10T22:07:41Z
1,408,234
<p>As previously described, you can (and should) use the <a href="http://docs.python.org/library/subprocess.html" rel="nofollow">subprocess</a> module.</p> <p>By default, <code>shell</code> parameter is <code>False</code>. This is good, and quite safe. Also, you don't need to pass the full path, just pass the executab...
0
2009-09-10T23:25:52Z
[ "python", "process", "fork", "subprocess", "popen" ]
Thread local storage in Python
1,408,171
<p>How do I use thread local storage in Python?</p> <h3>Related</h3> <ul> <li><a href="http://stackoverflow.com/questions/104983/what-is-thread-local-storage-in-python-and-why-do-i-need-it">What is “thread local storage” in Python, and why do I need it?</a> - This thread appears to be focused more on when variabl...
32
2009-09-10T23:03:33Z
1,408,178
<p>As noted in the question, Alex Martelli gives a solution <a href="http://stackoverflow.com/questions/1403471/efficient-way-to-determine-whether-a-particular-function-is-on-the-stack-in-pytho/1403485#1403485">here</a>. This function allows us to use a factory function to generate a default value for each thread.</p> ...
11
2009-09-10T23:05:44Z
[ "python", "multithreading", "thread-local-storage" ]
Thread local storage in Python
1,408,171
<p>How do I use thread local storage in Python?</p> <h3>Related</h3> <ul> <li><a href="http://stackoverflow.com/questions/104983/what-is-thread-local-storage-in-python-and-why-do-i-need-it">What is “thread local storage” in Python, and why do I need it?</a> - This thread appears to be focused more on when variabl...
32
2009-09-10T23:03:33Z
1,408,192
<p>Can also write</p> <pre><code>import threading mydata = threading.local() mydata.x = 1 </code></pre> <p>mydata.x will only exist in the current thread</p>
4
2009-09-10T23:10:52Z
[ "python", "multithreading", "thread-local-storage" ]
Thread local storage in Python
1,408,171
<p>How do I use thread local storage in Python?</p> <h3>Related</h3> <ul> <li><a href="http://stackoverflow.com/questions/104983/what-is-thread-local-storage-in-python-and-why-do-i-need-it">What is “thread local storage” in Python, and why do I need it?</a> - This thread appears to be focused more on when variabl...
32
2009-09-10T23:03:33Z
13,240,093
<p>Thread local storage is useful for instance if you have a thread worker pool and each thread needs access to its own resource, like a network or database connection. Note that the <code>threading</code> module uses the regular concept of threads (which have access to the process global data), but these are not too u...
53
2012-11-05T20:46:39Z
[ "python", "multithreading", "thread-local-storage" ]
Thread local storage in Python
1,408,171
<p>How do I use thread local storage in Python?</p> <h3>Related</h3> <ul> <li><a href="http://stackoverflow.com/questions/104983/what-is-thread-local-storage-in-python-and-why-do-i-need-it">What is “thread local storage” in Python, and why do I need it?</a> - This thread appears to be focused more on when variabl...
32
2009-09-10T23:03:33Z
29,781,795
<p>Thread-local storage can simply be thought of as a namespace (with values accessed via attribute notation). The difference is that each thread transparently gets its own set of attributes/values, so that one thread doesn't see the values from another thread.</p> <p>Just like an ordinary object, you can create multi...
9
2015-04-21T19:49:46Z
[ "python", "multithreading", "thread-local-storage" ]
Nice Python Decorators
1,408,253
<p>How do I nicely write a decorator?</p> <p>In particular issues include: compatibility with other decorators, preserving of signatures, etc.</p> <p>I would like to avoid dependency on the decorator module if possible, but if there were sufficient advantages, then I would consider it.</p> <p>Related</p> <ul> <li><...
3
2009-09-10T23:31:09Z
1,408,412
<p>Use functools to preserve the name and doc. The signature won't be preserved.</p> <p>Directly from the <a href="http://docs.python.org/library/functools.html" rel="nofollow">doc</a>. </p> <pre><code>&gt;&gt;&gt; from functools import wraps &gt;&gt;&gt; def my_decorator(f): ... @wraps(f) ... def wrapper(*ar...
6
2009-09-11T00:20:52Z
[ "python", "decorator" ]
Nice Python Decorators
1,408,253
<p>How do I nicely write a decorator?</p> <p>In particular issues include: compatibility with other decorators, preserving of signatures, etc.</p> <p>I would like to avoid dependency on the decorator module if possible, but if there were sufficient advantages, then I would consider it.</p> <p>Related</p> <ul> <li><...
3
2009-09-10T23:31:09Z
1,408,431
<p>Writing a good decorator is no different then writing a good function. Which means, ideally, using docstrings and making sure the decorator is included in your testing framework.</p> <p>You should definitely use either the <code>decorator</code> library or, better, the <code>functools.wraps()</code> decorator in t...
5
2009-09-11T00:28:27Z
[ "python", "decorator" ]
Get file creation time with Python on linux
1,408,272
<p>os.stat returns st_mtime and st_ctime attributes, the modification time is st_mtime and st_ctime "change time" on POSIX. is there any function that return the creation time of a file using python and under Linux?</p>
18
2009-09-10T23:35:39Z
1,408,281
<p><a href="http://www.faqs.org/faqs/unix-faq/faq/part3/section-1.html">You probably</a> <a href="http://linux.die.net/man/2/stat">can't.</a>:</p> <blockquote> <p>3.1) How do I find the creation time of a file?</p> <p>You can't - it isn't stored anywhere. Files have a last-modified time (shown by "ls -l")...
25
2009-09-10T23:38:21Z
[ "python", "linux" ]
Get file creation time with Python on linux
1,408,272
<p>os.stat returns st_mtime and st_ctime attributes, the modification time is st_mtime and st_ctime "change time" on POSIX. is there any function that return the creation time of a file using python and under Linux?</p>
18
2009-09-10T23:35:39Z
1,408,287
<p>try:</p> <pre><code>st_birthtime </code></pre> <p>It isnt' guaranteed to be available on all systems though. From the docs:</p> <blockquote> <p>On some Unix systems (such as Linux), the following attributes may also be available: st_blocks (number of blocks allocated for file), st_blksize (filesystem b...
13
2009-09-10T23:39:19Z
[ "python", "linux" ]
Get file creation time with Python on linux
1,408,272
<p>os.stat returns st_mtime and st_ctime attributes, the modification time is st_mtime and st_ctime "change time" on POSIX. is there any function that return the creation time of a file using python and under Linux?</p>
18
2009-09-10T23:35:39Z
31,150,571
<p>You might explain why you want to do this.</p> <p>An indirect solution might be to use some <a href="https://en.wikipedia.org/wiki/Revision_control" rel="nofollow">revision control</a> system (a.k.a. version control system = VCS) to manage the files whose birth time is needed.</p> <p>So you could use <a href="http...
1
2015-07-01T00:10:20Z
[ "python", "linux" ]
Get file creation time with Python on linux
1,408,272
<p>os.stat returns st_mtime and st_ctime attributes, the modification time is st_mtime and st_ctime "change time" on POSIX. is there any function that return the creation time of a file using python and under Linux?</p>
18
2009-09-10T23:35:39Z
31,246,246
<p>According to a thread <a href="http://www.linuxquestions.org/questions/linux-enterprise-47/how-to-find-creation-date-of-a-file-in-rhel-5-a-4175518213/" rel="nofollow">here</a> <em>OS X's HFS and Microsoft's NTFS also both track the birth time, and I'm told the OS X and Cygwin versions of stat() return this informati...
1
2015-07-06T12:45:50Z
[ "python", "linux" ]
Get file creation time with Python on linux
1,408,272
<p>os.stat returns st_mtime and st_ctime attributes, the modification time is st_mtime and st_ctime "change time" on POSIX. is there any function that return the creation time of a file using python and under Linux?</p>
18
2009-09-10T23:35:39Z
39,476,826
<p>Certain file systems do support recording the birth time, but Linux does not provide an interface for obtaining it.</p> <p>See <a href="http://lwn.net/Articles/397442/" rel="nofollow">http://lwn.net/Articles/397442/</a></p> <p>If one atempts to use the "stat" command to obtain it: % stat -c %w {file or dir}</p> <...
0
2016-09-13T18:32:11Z
[ "python", "linux" ]
Help with Python/Qt4 and QTableWidget column click
1,408,277
<p>I'm trying to learn PyQt4 and GUI design with QtDesigner. I've got my basic GUI designed, and I now want to capture when the user clicks on a column header.</p> <p>My thought is that I need to override QTableWidget, but I don't know how to attach to the signal. Here's my class so far:</p> <pre><code>class MyTabl...
0
2009-09-10T23:37:27Z
1,408,465
<p>OK, the SIGNAL needed is:</p> <pre><code>self.connect(self.horizontalHeader(), SIGNAL('sectionClicked(int)'), self.onClick) </code></pre>
2
2009-09-11T00:42:18Z
[ "python", "qt4", "pyqt4" ]
Python: NoneType errors.Do they look familiar
1,408,286
<p>I've been looking for the NoneType for half a day. I've put 'print' and dir() all through the generation of the Object represented by t2. I've looked at the data structure after the crash using 'post mortem' and nowhere can I find a NoneType. I was wondering if perhaps it's one of those errors that are initiated by ...
0
2009-09-10T23:38:55Z
1,408,303
<p>for some reason, at the point of the assert line, the value of <code>branch</code> is <strong><code>None</code></strong>. </p> <p>If your second exception is separate, Then most likely what is happening is the method call <code>self.removeSubtreeFromTree()</code> is returning None, instead of a sequence (like a tu...
2
2009-09-10T23:43:30Z
[ "python" ]
Python: NoneType errors.Do they look familiar
1,408,286
<p>I've been looking for the NoneType for half a day. I've put 'print' and dir() all through the generation of the Object represented by t2. I've looked at the data structure after the crash using 'post mortem' and nowhere can I find a NoneType. I was wondering if perhaps it's one of those errors that are initiated by ...
0
2009-09-10T23:38:55Z
1,408,304
<p><code>NoneType</code> is the type of the <code>None</code> object. So, in the first error, <code>branch</code> is <code>None</code>. The second error is tougher to diagnose without seeing the source code, but suggests that somewhere in <code>t2</code>, the data structure isn't exactly as you believe.</p> <p>When ...
5
2009-09-10T23:43:33Z
[ "python" ]
Python: NoneType errors.Do they look familiar
1,408,286
<p>I've been looking for the NoneType for half a day. I've put 'print' and dir() all through the generation of the Object represented by t2. I've looked at the data structure after the crash using 'post mortem' and nowhere can I find a NoneType. I was wondering if perhaps it's one of those errors that are initiated by ...
0
2009-09-10T23:38:55Z
1,408,419
<p>I agree with Managu that it's likely you've forgotten to return a value from a function. I do that all the time.</p> <p>As another possibility, I presume you are writing some kind of tree data structure. Is it possible that you're using None to indicate "this node has no children" and you aren't handling that cas...
1
2009-09-11T00:24:15Z
[ "python" ]
Python: NoneType errors.Do they look familiar
1,408,286
<p>I've been looking for the NoneType for half a day. I've put 'print' and dir() all through the generation of the Object represented by t2. I've looked at the data structure after the crash using 'post mortem' and nowhere can I find a NoneType. I was wondering if perhaps it's one of those errors that are initiated by ...
0
2009-09-10T23:38:55Z
1,408,510
<p>Another one that got me was in-place functions, like list.append() (can't use that in a function call, list.append() returns None and changes the variable).</p> <p>I spent the better part of a day and a half chasing that bug....</p>
0
2009-09-11T00:58:12Z
[ "python" ]
NumPy array slice using None
1,408,311
<p>This had me scratching my head for a while. I was unintentionally slicing an array with None and getting something other than an error (I expected an error). Instead, it returns an array with an extra dimension.</p> <pre><code>&gt;&gt;&gt; import numpy &gt;&gt;&gt; a = numpy.arange(4).reshape(2,2) &gt;&gt;&gt; a ...
12
2009-09-10T23:45:07Z
1,408,435
<p>Using None is equivalent to using <code>numpy.newaxis</code>, so yes, it's intentional. In fact, they're the same thing, but, of course, <code>newaxis</code> spells it out better.</p> <p><a href="http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#numpy.newaxis">The docs</a></p> <p><a href="http://stac...
16
2009-09-11T00:29:39Z
[ "python", "arrays", "numpy" ]
send an arbitrary number of inputs from python to a .exe
1,408,326
<p><pre><code> p = subprocess.Popen(args = "myprog.exe" + " " + str(input1) + " " + str(input2) + " " + str(input3) + " " + strpoints, stdout = subprocess.PIPE) </pre></code></p> <p>in the code above, input1, input2, and input3 are all...
2
2009-09-10T23:48:56Z
1,408,334
<p>Try using string.join: </p> <pre><code>p = subprocess.Popen(args = "myprog.exe" + " " + str(input1) + " " + str(input2) + " " + str(input3) + " " + " ".join(strpoints), stdout = subprocess.PIPE) </code></pre>
4
2009-09-10T23:50:59Z
[ "python", "executable" ]
send an arbitrary number of inputs from python to a .exe
1,408,326
<p><pre><code> p = subprocess.Popen(args = "myprog.exe" + " " + str(input1) + " " + str(input2) + " " + str(input3) + " " + strpoints, stdout = subprocess.PIPE) </pre></code></p> <p>in the code above, input1, input2, and input3 are all...
2
2009-09-10T23:48:56Z
1,408,346
<p>args can be a sequence:</p> <pre><code>p = subprocess.Popen(args = ["myprog.exe"] + [str(x) for x in [input1,input2,input3]] + strpoints,stdout = subprocess.PIPE) </code></pre> <p>This is more correct if your arguments contain shell metacharacters e.g. ' * ...
7
2009-09-10T23:55:37Z
[ "python", "executable" ]
send an arbitrary number of inputs from python to a .exe
1,408,326
<p><pre><code> p = subprocess.Popen(args = "myprog.exe" + " " + str(input1) + " " + str(input2) + " " + str(input3) + " " + strpoints, stdout = subprocess.PIPE) </pre></code></p> <p>in the code above, input1, input2, and input3 are all...
2
2009-09-10T23:48:56Z
1,408,428
<p>Avoid concatenating all arguments into one string using that string.</p> <p>It's a lot simpler and better and safer to just pass a sequence (list or tuple) of arguments. This is specially true if any argument contains a space character (which is quite common for filenames).</p>
1
2009-09-11T00:26:46Z
[ "python", "executable" ]
send an arbitrary number of inputs from python to a .exe
1,408,326
<p><pre><code> p = subprocess.Popen(args = "myprog.exe" + " " + str(input1) + " " + str(input2) + " " + str(input3) + " " + strpoints, stdout = subprocess.PIPE) </pre></code></p> <p>in the code above, input1, input2, and input3 are all...
2
2009-09-10T23:48:56Z
1,408,449
<p>Any thought that you might want to enclose those strings in quotes, in case they have embedded spaces? Something like:</p> <pre><code>if strpoints: finalargs = '"' + '" "'.join(strpoints) + '"' else: finalargs = "" p = subprocess.Popen(args = "myprog.exe" + " " + str(input1) + " " + ...
0
2009-09-11T00:35:11Z
[ "python", "executable" ]
Keyboard Interrupts with python's multiprocessing Pool
1,408,356
<p>How can I handle KeyboardInterrupt events with python's multiprocessing Pools? Here is a simple example:</p> <pre><code>from multiprocessing import Pool from time import sleep from sys import exit def slowly_square(i): sleep(1) return i*i def go(): pool = Pool(8) try: results = pool.map(sl...
78
2009-09-10T23:59:35Z
1,408,425
<p>Strangely enough it looks like you have to handle the <code>KeyboardInterrupt</code> in the children as well. I would have expected this to work as written... try changing <code>slowly_square</code> to:</p> <pre><code>def slowly_square(i): try: sleep(1) return i * i except KeyboardInterrupt...
-4
2009-09-11T00:26:22Z
[ "python", "multiprocessing", "pool", "keyboardinterrupt" ]