title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
How to use IPython with IronPython
1,849,652
<p>What is the procedure to get IPython to use IronPython as it's Python interpreter?</p> <p>I know there were previously some issues: <a href="http://stackoverflow.com/questions/1160501/what-is-required-to-use-ipython-in-ironpython">http://stackoverflow.com/questions/1160501/what-is-required-to-use-ipython-in-ironpy...
8
2009-12-04T21:07:59Z
17,554,307
<p>It now works as of IronPython 2.7.3 Alpha 1!</p> <p>source: <a href="https://github.com/ipython/ipython/wiki/Frequently-asked-questions#wiki-q-can-ipython-run-under-ironpython" rel="nofollow">https://github.com/ipython/ipython/wiki/Frequently-asked-questions#wiki-q-can-ipython-run-under-ironpython</a></p>
2
2013-07-09T17:15:05Z
[ "python", "ironpython", "ipython" ]
What's the best python idiom for grouping a list of items into groups of a specific max size?
1,849,741
<p>I want to write a function that takes items from a list and groups them into groups of size n.</p> <p>Ie, for n = 5, [1, 2, 3, 4, 5, 6, 7] would become [[1, 2, 3, 4, 5], [6, 7]].</p> <p>What's the best python idiomatic way to do this?</p>
2
2009-12-04T21:27:18Z
1,849,817
<p>I don't know of a good command to do this, but here's a way to do it with a list comprehension:</p> <pre><code>l = [1,2,3,4,5,6,7] n = 5 newlist = [l[i:i+n] for i in range(0,len(l),n)] </code></pre> <p>Edit: as a commenter pointed out, I had accidentally put l[i:i+n] in a list.</p>
1
2009-12-04T21:40:00Z
[ "python" ]
What's the best python idiom for grouping a list of items into groups of a specific max size?
1,849,741
<p>I want to write a function that takes items from a list and groups them into groups of size n.</p> <p>Ie, for n = 5, [1, 2, 3, 4, 5, 6, 7] would become [[1, 2, 3, 4, 5], [6, 7]].</p> <p>What's the best python idiomatic way to do this?</p>
2
2009-12-04T21:27:18Z
1,849,818
<p>You could do this:</p> <pre><code>[a[x:x+n] for x in range(0, len(a), n)] </code></pre> <p>(In Python 2, use <code>xrange</code> for efficiency; in Python 3 use <code>range</code> as above.)</p>
2
2009-12-04T21:40:04Z
[ "python" ]
What's the best python idiom for grouping a list of items into groups of a specific max size?
1,849,741
<p>I want to write a function that takes items from a list and groups them into groups of size n.</p> <p>Ie, for n = 5, [1, 2, 3, 4, 5, 6, 7] would become [[1, 2, 3, 4, 5], [6, 7]].</p> <p>What's the best python idiomatic way to do this?</p>
2
2009-12-04T21:27:18Z
1,849,826
<pre><code>[a[n*k:n*(k+1)] for k in range(0,len(a)/n+1)] </code></pre>
0
2009-12-04T21:42:06Z
[ "python" ]
What's the best python idiom for grouping a list of items into groups of a specific max size?
1,849,741
<p>I want to write a function that takes items from a list and groups them into groups of size n.</p> <p>Ie, for n = 5, [1, 2, 3, 4, 5, 6, 7] would become [[1, 2, 3, 4, 5], [6, 7]].</p> <p>What's the best python idiomatic way to do this?</p>
2
2009-12-04T21:27:18Z
1,850,706
<p>Solutions using ranges with steps only work on sequences such as lists and tuples (not iterators). They also aren't as efficient as they can be, since they access the sequence many times instead of iterating over it once.</p> <p>Here's a version which supports iterators and only iterates over the input once, creati...
1
2009-12-05T01:14:06Z
[ "python" ]
Pyjamas import statements
1,849,909
<p>I'm starting to use Pyjamas and I'm running into some annoyances. I have to import a lot of stuff to make a script work well. For example, to make a button I need to first</p> <pre><code>from pyjamas.ui.Button import Button </code></pre> <p>and then I can use <code>Button</code>. Note that</p> <pre><code>impor...
0
2009-12-04T21:55:41Z
1,850,161
<p>If you want to be able to say <code>Button.Button</code>, then instead of</p> <pre><code>import pyjamas.ui.Button </code></pre> <p>you should write</p> <pre><code>from pyjamas.ui import Button </code></pre> <p>Otherwise you need to use <code>pyjamas.ui.Button.Button</code>. What ends up in your namespace is what...
5
2009-12-04T22:47:29Z
[ "python", "coding-style", "import", "pyjamas" ]
Looking for feedback on my program design
1,849,924
<p>I'm aware that SO is for questions but overall the aim is to help people learn so I figured I'd try my hand at sharing some code and asking for feedback on it.</p> <p><hr></p> <p>I'm looking to create a program that will rely on random numbers, specifically dice. These will be presented in the form of "2D6", "4D10...
0
2009-12-04T21:58:43Z
1,849,950
<p>Superficially, there's <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP08</a>; in particular, the use of 4 spaces for an indent vs using tab characters.</p> <p>It also seems like you have a lot of accidental complexity here, but I'd have to chew on it some more to understand. It seems like a s...
1
2009-12-04T22:03:17Z
[ "python" ]
Looking for feedback on my program design
1,849,924
<p>I'm aware that SO is for questions but overall the aim is to help people learn so I figured I'd try my hand at sharing some code and asking for feedback on it.</p> <p><hr></p> <p>I'm looking to create a program that will rely on random numbers, specifically dice. These will be presented in the form of "2D6", "4D10...
0
2009-12-04T21:58:43Z
1,851,938
<p>I think your approach makes for a lot of complexity: you're trying to solve the hard problem (parsing the input) at the same time you're solving the less-hard problem (doing the dice-rolling). It's easier if you separate the problems.</p> <p>A class to roll dice is relatively easy to write. Two things I'm doing ...
3
2009-12-05T11:24:10Z
[ "python" ]
Looking for feedback on my program design
1,849,924
<p>I'm aware that SO is for questions but overall the aim is to help people learn so I figured I'd try my hand at sharing some code and asking for feedback on it.</p> <p><hr></p> <p>I'm looking to create a program that will rely on random numbers, specifically dice. These will be presented in the form of "2D6", "4D10...
0
2009-12-04T21:58:43Z
1,853,100
<p>The <a href="http://pyparsing.wikispaces.com/Examples" rel="nofollow">pyparsing examples page</a> includes a similar <a href="http://pyparsing.wikispaces.com/file/view/dice2.py" rel="nofollow">dice expression parser and roller</a>, including these test cases:</p> <pre><code>D5+2d6*3-5.5+4d6 D5+2d6*3-5.5+4d6.takeHig...
1
2009-12-05T19:02:13Z
[ "python" ]
Creating a generator expression from a list in python
1,850,223
<p>What is the best way to do the following in Python:</p> <pre><code>for item in [ x.attr for x in some_list ]: do_something_with(item) </code></pre> <p>This may be a nub question, but isn't the list comprehension generating a new list that we don't need and just taking up memory? Wouldn't it be better if we cou...
3
2009-12-04T23:00:35Z
1,850,252
<p>Yes (to both of your questions).</p> <p>By using parentheses instead of brackets you can make what's called a "generator expression" for that sequence, which does exactly what you've proposed. It lets you iterate over the sequence without allocating a list to hold all the elements simultaneously.</p> <pre><code>fo...
9
2009-12-04T23:06:48Z
[ "python", "list", "generator", "functional-programming" ]
Creating a generator expression from a list in python
1,850,223
<p>What is the best way to do the following in Python:</p> <pre><code>for item in [ x.attr for x in some_list ]: do_something_with(item) </code></pre> <p>This may be a nub question, but isn't the list comprehension generating a new list that we don't need and just taking up memory? Wouldn't it be better if we cou...
3
2009-12-04T23:00:35Z
1,853,335
<p>Why not just:</p> <pre><code>for x in some_list: do_something_with(x.attr) </code></pre>
1
2009-12-05T20:20:27Z
[ "python", "list", "generator", "functional-programming" ]
Creating a generator expression from a list in python
1,850,223
<p>What is the best way to do the following in Python:</p> <pre><code>for item in [ x.attr for x in some_list ]: do_something_with(item) </code></pre> <p>This may be a nub question, but isn't the list comprehension generating a new list that we don't need and just taking up memory? Wouldn't it be better if we cou...
3
2009-12-04T23:00:35Z
17,375,983
<p>This question is tagged <code>functional-programming</code> without an appropriate answer, so here's a functional solution:</p> <pre class="lang-py prettyprint-override"><code>from operator import itemgetter map(do_something_with, map(itemgetter('attr'), some_list)) </code></pre> <p>Python 3's <code>map()</code> ...
0
2013-06-29T02:04:58Z
[ "python", "list", "generator", "functional-programming" ]
Python: Change class type name
1,850,289
<p>How would you change a class type name to something other than classobj?</p> <pre><code>class bob(): pass foo = bob print "%s" % type(foo).__name__ </code></pre> <p>which gets me 'classobj'.</p>
0
2009-12-04T23:14:23Z
1,850,306
<p>In your example, you've defined <code>foo</code> as a reference to the class definition of <code>bob</code>, not to an instance of bob. The type of an (old-style) class is indeed <code>classobj</code>.</p> <p>If you instantiate <code>bob</code>, on the other hand, the result will be different:</p> <pre><code># exa...
12
2009-12-04T23:17:52Z
[ "python" ]
Python: Change class type name
1,850,289
<p>How would you change a class type name to something other than classobj?</p> <pre><code>class bob(): pass foo = bob print "%s" % type(foo).__name__ </code></pre> <p>which gets me 'classobj'.</p>
0
2009-12-04T23:14:23Z
1,850,810
<pre><code>class DifferentTypeName(type): pass class bob: __metaclass__ = DifferentTypeName foo = bob print "%s" % type(foo).__name__ </code></pre> <p>emits <code>DifferentTypeName</code>, as you require. It seems unlikely that this is actually what you want (or need), but, hey, it <em>is</em> the way to do exact...
9
2009-12-05T01:48:08Z
[ "python" ]
What are the pros/cons of the various Twitter API libraries for Python?
1,850,443
<p>It seems there are at least five <a href="https://dev.twitter.com/docs/twitter-libraries#python" rel="nofollow">Python libraries</a> for the Twitter API. Can those who have used them comment on your experiences?</p>
5
2009-12-04T23:54:10Z
1,850,455
<p>I just use <code>urllib2</code> with <code>simplejson</code>. For something like a REST call, a library will usually just get in your way.</p>
1
2009-12-04T23:59:37Z
[ "python", "twitter" ]
What are the pros/cons of the various Twitter API libraries for Python?
1,850,443
<p>It seems there are at least five <a href="https://dev.twitter.com/docs/twitter-libraries#python" rel="nofollow">Python libraries</a> for the Twitter API. Can those who have used them comment on your experiences?</p>
5
2009-12-04T23:54:10Z
1,850,473
<p>I personally use <a href="http://mike.verdone.ca/twitter/" rel="nofollow">http://mike.verdone.ca/twitter/</a>. I took a look at some other libraries but they seemed to be much bigger than what I needed but YMMV.</p>
1
2009-12-05T00:07:13Z
[ "python", "twitter" ]
What are the pros/cons of the various Twitter API libraries for Python?
1,850,443
<p>It seems there are at least five <a href="https://dev.twitter.com/docs/twitter-libraries#python" rel="nofollow">Python libraries</a> for the Twitter API. Can those who have used them comment on your experiences?</p>
5
2009-12-04T23:54:10Z
1,850,493
<p>My experience with the Twitter REST APIs is that it's critical to handle errors well with retries. If you write everything as if all your results will be successful, you'll end up doing a lot of extra work going back to each REST call and dealing with errors.</p> <p>I haven't used any of these libraries, but automa...
2
2009-12-05T00:11:57Z
[ "python", "twitter" ]
What are the pros/cons of the various Twitter API libraries for Python?
1,850,443
<p>It seems there are at least five <a href="https://dev.twitter.com/docs/twitter-libraries#python" rel="nofollow">Python libraries</a> for the Twitter API. Can those who have used them comment on your experiences?</p>
5
2009-12-04T23:54:10Z
1,850,523
<p>I used <a href="http://code.google.com/p/python-twitter/" rel="nofollow">python-twitter</a> for my <a href="http://you.dontlike.us/gitweb.cgi?p=mwalling/arduino-twitdehumid.git;a=blob;f=twitdehumid.py;h=f420d4a30ff710318fcf88b515b3782f2ca43c56;hb=HEAD" rel="nofollow">Twittering Dehumidifer</a> with no complaints, al...
0
2009-12-05T00:17:47Z
[ "python", "twitter" ]
What are the pros/cons of the various Twitter API libraries for Python?
1,850,443
<p>It seems there are at least five <a href="https://dev.twitter.com/docs/twitter-libraries#python" rel="nofollow">Python libraries</a> for the Twitter API. Can those who have used them comment on your experiences?</p>
5
2009-12-04T23:54:10Z
1,850,553
<p>I'm using <a href="http://devblog.yedda.com/wp-content/uploads/2007/05/yeddatwitter-v01.zip" rel="nofollow">Yedda.Twitter.dll</a> to work with IronPython. So far it has worked well and I am able to use it to post tweets. I have decompiled it and read it a bit and it seems to support most other functions. Although, I...
0
2009-12-05T00:24:32Z
[ "python", "twitter" ]
What are the pros/cons of the various Twitter API libraries for Python?
1,850,443
<p>It seems there are at least five <a href="https://dev.twitter.com/docs/twitter-libraries#python" rel="nofollow">Python libraries</a> for the Twitter API. Can those who have used them comment on your experiences?</p>
5
2009-12-04T23:54:10Z
2,199,736
<p>Since I'm looking at this myself I think that things stand this way.</p> <ol> <li>python-twitter is the defacto old API stuff, it works very well unless you need new stuff (ie: streaming) They are several "third party" packages that provide some new functionality like <a href="http://code.google.com/p/oauth-python-...
1
2010-02-04T12:50:35Z
[ "python", "twitter" ]
Adding an argument to a decorator
1,850,463
<p>I have this decorator, used to decorate a django view when I do not want the view to be executed if the <code>share</code> argument is <code>True</code> (handled by middleware)</p> <pre><code>class no_share(object): def __init__(self, view): self.view = view def __call__(self, request, *args, **kwa...
5
2009-12-05T00:03:29Z
1,850,474
<pre><code>class no_share(object): def __init__(self, foo, view): self.foo = foo self.view = view </code></pre>
1
2009-12-05T00:07:22Z
[ "python", "django", "decorator" ]
Adding an argument to a decorator
1,850,463
<p>I have this decorator, used to decorate a django view when I do not want the view to be executed if the <code>share</code> argument is <code>True</code> (handled by middleware)</p> <pre><code>class no_share(object): def __init__(self, view): self.view = view def __call__(self, request, *args, **kwa...
5
2009-12-05T00:03:29Z
1,850,485
<p>I hope <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=240845" rel="nofollow">this</a> article by Bruce Eckel helps.</p> <p><strong>Upd:</strong> According to the article your code will look like this:</p> <pre><code>class no_share(object): def __init__(self, arg1): self.arg1 = arg1 def...
7
2009-12-05T00:10:41Z
[ "python", "django", "decorator" ]
Adding an argument to a decorator
1,850,463
<p>I have this decorator, used to decorate a django view when I do not want the view to be executed if the <code>share</code> argument is <code>True</code> (handled by middleware)</p> <pre><code>class no_share(object): def __init__(self, view): self.view = view def __call__(self, request, *args, **kwa...
5
2009-12-05T00:03:29Z
1,850,592
<p>Since it seems you're getting this wrong somewhere, here's a more complete example which may help you see what you're doing wrong. Using this as a drop-in should work.</p> <pre><code>class no_share(object): def __init__(self, view, attr_name): self.view = view self.attr_name = attr_name def...
0
2009-12-05T00:35:45Z
[ "python", "django", "decorator" ]
Adding an argument to a decorator
1,850,463
<p>I have this decorator, used to decorate a django view when I do not want the view to be executed if the <code>share</code> argument is <code>True</code> (handled by middleware)</p> <pre><code>class no_share(object): def __init__(self, view): self.view = view def __call__(self, request, *args, **kwa...
5
2009-12-05T00:03:29Z
1,850,776
<p>The Bruce Eckel <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=240845" rel="nofollow">article</a> that Li0liQ mentioned should be helpful in figuring this out. Decorators with and with out arguments behave slightly differently. The big difference is that when you pass arguments the __call__ method gets...
4
2009-12-05T01:34:44Z
[ "python", "django", "decorator" ]
Adding an argument to a decorator
1,850,463
<p>I have this decorator, used to decorate a django view when I do not want the view to be executed if the <code>share</code> argument is <code>True</code> (handled by middleware)</p> <pre><code>class no_share(object): def __init__(self, view): self.view = view def __call__(self, request, *args, **kwa...
5
2009-12-05T00:03:29Z
1,851,606
<p>I think closure may works here.</p> <pre><code>def no_share(attr): def _no_share(decorated): def func(self, request, *args, **kwargs): """Don't let them in if it's shared""" if kwargs.get(attr, True): from django.http import Http404 raise Http404(...
1
2009-12-05T08:43:54Z
[ "python", "django", "decorator" ]
Adding an argument to a decorator
1,850,463
<p>I have this decorator, used to decorate a django view when I do not want the view to be executed if the <code>share</code> argument is <code>True</code> (handled by middleware)</p> <pre><code>class no_share(object): def __init__(self, view): self.view = view def __call__(self, request, *args, **kwa...
5
2009-12-05T00:03:29Z
9,124,990
<p>I know this ia a little late .. but I didn't see any mentions for this way of doing things (probably because it didn't exist when the question was asked), but, in the interests of completeness I found it useful to look at how Django themselves implemented such a thing. Have a look at:</p> <p>django.views.decorator...
0
2012-02-03T07:13:32Z
[ "python", "django", "decorator" ]
Python fraction of seconds
1,850,607
<p>What is the best way to handle portions of a second in Python? The datetime library is excellent, but as far as I can tell it cannot handle any unit less than a second.</p>
7
2009-12-05T00:40:48Z
1,850,623
<p>For what purpose? import time -> time.clock() returns the current time in milliseconds, so it can be used for timing purposes to millisecond accuracy.</p>
0
2009-12-05T00:47:19Z
[ "python", "datetime" ]
Python fraction of seconds
1,850,607
<p>What is the best way to handle portions of a second in Python? The datetime library is excellent, but as far as I can tell it cannot handle any unit less than a second.</p>
7
2009-12-05T00:40:48Z
1,850,626
<p>To get a better answer you'll need to specify your question further, but this should show at least how <a href="http://docs.python.org/library/datetime.html#datetime.datetime.microsecond" rel="nofollow">datetime can handle microseconds</a>:</p> <pre><code>&gt;&gt;&gt; from datetime import datetime &gt;&gt;&gt; t=da...
4
2009-12-05T00:48:52Z
[ "python", "datetime" ]
Python fraction of seconds
1,850,607
<p>What is the best way to handle portions of a second in Python? The datetime library is excellent, but as far as I can tell it cannot handle any unit less than a second.</p>
7
2009-12-05T00:40:48Z
1,851,645
<p>In the datetime module, the datetime, time, and timedelta classes all have the smallest resolution of microseconds:</p> <pre><code>&gt;&gt;&gt; from datetime import datetime, timedelta &gt;&gt;&gt; now = datetime.now() &gt;&gt;&gt; now datetime.datetime(2009, 12, 4, 23, 3, 27, 343000) &gt;&gt;&gt; now.microsecond 3...
11
2009-12-05T09:02:43Z
[ "python", "datetime" ]
Python fraction of seconds
1,850,607
<p>What is the best way to handle portions of a second in Python? The datetime library is excellent, but as far as I can tell it cannot handle any unit less than a second.</p>
7
2009-12-05T00:40:48Z
1,852,366
<p>NumPy 1.4 (in release candidate stage) has support for its own Date and DateArray objects. The one advantage is that it supports frequencies smaller than femtoseconds: <a href="http://projects.scipy.org/numpy/browser/trunk/doc/neps/datetime-proposal.rst" rel="nofollow">http://projects.scipy.org/numpy/browser/trunk/...
1
2009-12-05T14:41:32Z
[ "python", "datetime" ]
Python: TypeError: 'float' object is not callable
1,850,633
<p>I am trying to join 2 strings using this code:</p> <pre><code>def __get_temp(self): return float(self.ask('RS')) def __set_temp(self, temp): set = ('SS' + repr(temp)) stat = self.ask(set) return self.check(stat) temp = property(__get_temp, __set_temp) </code></pre> <p>Once together, I then send a...
0
2009-12-05T00:52:22Z
1,850,651
<p>It looks like you are trying to set the property temp, but what you're actually doing is <em>getting</em> the property and then trying to call it as function with the parameter 13. The syntax for setting is:</p> <pre><code>chil.temp = 13 </code></pre>
7
2009-12-05T00:57:38Z
[ "python", "types" ]
Objective reasons for using Python or Ruby for a new REST Web API
1,850,640
<p>So this thread is definitely NOT a thread for why Python is better than Ruby or the inverse. Instead, this thread is for objective criticism on why you would pick one over the other to write a RESTful web API that's going to be used by many different clients, (mobile, web browsers, tablets etc).</p> <p>Again, don't...
6
2009-12-05T00:55:24Z
1,850,652
<p>I know Ruby, don't know python... you can see which way I'm leaning toward, right?</p>
5
2009-12-05T00:57:39Z
[ "python", "ruby", "web-services", "api", "rest" ]
Objective reasons for using Python or Ruby for a new REST Web API
1,850,640
<p>So this thread is definitely NOT a thread for why Python is better than Ruby or the inverse. Instead, this thread is for objective criticism on why you would pick one over the other to write a RESTful web API that's going to be used by many different clients, (mobile, web browsers, tablets etc).</p> <p>Again, don't...
6
2009-12-05T00:55:24Z
1,850,653
<p>Choose the one you're most familiar with and most likely to get things done with the fastest.</p>
4
2009-12-05T00:57:40Z
[ "python", "ruby", "web-services", "api", "rest" ]
Objective reasons for using Python or Ruby for a new REST Web API
1,850,640
<p>So this thread is definitely NOT a thread for why Python is better than Ruby or the inverse. Instead, this thread is for objective criticism on why you would pick one over the other to write a RESTful web API that's going to be used by many different clients, (mobile, web browsers, tablets etc).</p> <p>Again, don't...
6
2009-12-05T00:55:24Z
1,850,684
<p>Yeah, flip a coin. The truth is that you're going to find minimalist frameworks in either language. <a href="http://heroku.com" rel="nofollow">Heroku</a> is a pretty strong reason to say Ruby but there may be other similar hosts for Python. But Heroku makes it stupid easy to deploy your api into the cloud whether it...
4
2009-12-05T01:06:09Z
[ "python", "ruby", "web-services", "api", "rest" ]
Objective reasons for using Python or Ruby for a new REST Web API
1,850,640
<p>So this thread is definitely NOT a thread for why Python is better than Ruby or the inverse. Instead, this thread is for objective criticism on why you would pick one over the other to write a RESTful web API that's going to be used by many different clients, (mobile, web browsers, tablets etc).</p> <p>Again, don't...
6
2009-12-05T00:55:24Z
1,850,701
<p>I would say the important thing is that regardless of which you choose, make sure that your choice does not leak through your REST API. It should not matter to the client of your API which you chose.</p>
5
2009-12-05T01:13:18Z
[ "python", "ruby", "web-services", "api", "rest" ]
Objective reasons for using Python or Ruby for a new REST Web API
1,850,640
<p>So this thread is definitely NOT a thread for why Python is better than Ruby or the inverse. Instead, this thread is for objective criticism on why you would pick one over the other to write a RESTful web API that's going to be used by many different clients, (mobile, web browsers, tablets etc).</p> <p>Again, don't...
6
2009-12-05T00:55:24Z
1,850,743
<p>I think they are fairly evenly matched in features. I prefer Python, but I have been using it for over a decade so I freely admit that what follows is totally biased.</p> <p>IMHO Python is more mature - there are more libraries for it (although Ruby may be catching up), and the included libraries I think are bette...
2
2009-12-05T01:24:50Z
[ "python", "ruby", "web-services", "api", "rest" ]
Objective reasons for using Python or Ruby for a new REST Web API
1,850,640
<p>So this thread is definitely NOT a thread for why Python is better than Ruby or the inverse. Instead, this thread is for objective criticism on why you would pick one over the other to write a RESTful web API that's going to be used by many different clients, (mobile, web browsers, tablets etc).</p> <p>Again, don't...
6
2009-12-05T00:55:24Z
1,852,162
<p>Either will do a great job and you'll gain in other ways from learning something new. Why not spend as couple of days with each? See how far you can get with a simple subset of the problem, then see how you feel. For bonus points report back here and answer your own question! </p>
1
2009-12-05T13:05:49Z
[ "python", "ruby", "web-services", "api", "rest" ]
Objective reasons for using Python or Ruby for a new REST Web API
1,850,640
<p>So this thread is definitely NOT a thread for why Python is better than Ruby or the inverse. Instead, this thread is for objective criticism on why you would pick one over the other to write a RESTful web API that's going to be used by many different clients, (mobile, web browsers, tablets etc).</p> <p>Again, don't...
6
2009-12-05T00:55:24Z
1,853,203
<p>Ruby + <a href="http://www.sinatrarb.com" rel="nofollow">Sinatra</a></p> <p>Very easy to use with/as rack middleware - someone's already mentioned heroku</p>
2
2009-12-05T19:35:52Z
[ "python", "ruby", "web-services", "api", "rest" ]
Pylucene eclipse plugin
1,850,717
<p>Is there a Pylucene eclipse plugin? or am I missing something? </p> <p>I want it for Auto complete. Is the import structure same as java lucene</p>
0
2009-12-05T01:16:57Z
1,850,760
<p>Assuming you're using <a href="http://pydev.org/" rel="nofollow">PyDev</a>, you need to add PyLucene to your import path. This can be done in the preferences pane somewhere under the PyDev section. (Sorry, I don't have PyDev installed on this computer so I can't be more specific.) Not having used PyLucene I can't te...
1
2009-12-05T01:30:02Z
[ "java", "python", "lucene", "pylucene" ]
Django Delete all but last five of queryset
1,851,197
<p>I have a super simple django model here:</p> <pre><code>class Notification(models.Model): message = models.TextField() user = models.ForeignKey(User) timestamp = models.DateTimeField(default=datetime.datetime.now) </code></pre> <p>Using ajax, I check for new messages every minute. I only show the five ...
18
2009-12-05T05:17:29Z
1,852,789
<p>Use an inner query to get the set of items you want to keep and then filter on them.</p> <pre><code>objects_to_keep = Notification.objects.filter(user=user).order_by('-created_at')[:5] Notification.objects.exclude(pk__in=objects_to_keep).delete() </code></pre> <p>Double check this before you use it. I have found ...
11
2009-12-05T17:20:49Z
[ "python", "django" ]
Django Delete all but last five of queryset
1,851,197
<p>I have a super simple django model here:</p> <pre><code>class Notification(models.Model): message = models.TextField() user = models.ForeignKey(User) timestamp = models.DateTimeField(default=datetime.datetime.now) </code></pre> <p>Using ajax, I check for new messages every minute. I only show the five ...
18
2009-12-05T05:17:29Z
1,853,168
<p>this is how i ended up doing this.</p> <pre><code> notes = Notification.objects.filter(user=self.user) for note in notes[4:]: note.delete() </code></pre> <p>because i'm doing this in the save method, the only way the loop would ever have to run more than once would be if the user got multiple notifi...
8
2009-12-05T19:25:23Z
[ "python", "django" ]
Django Delete all but last five of queryset
1,851,197
<p>I have a super simple django model here:</p> <pre><code>class Notification(models.Model): message = models.TextField() user = models.ForeignKey(User) timestamp = models.DateTimeField(default=datetime.datetime.now) </code></pre> <p>Using ajax, I check for new messages every minute. I only show the five ...
18
2009-12-05T05:17:29Z
20,996,456
<p>This is a bit old, but I believe you can do the following:</p> <pre><code>notes = Notification.objects.filter(user=self.user)[:4] Notification.objects.exclude(pk__in=list(notes)).delete() # list() forces a database hit. </code></pre> <p>It costs two hits, but avoids using the for loop with transactions middleware...
13
2014-01-08T13:03:30Z
[ "python", "django" ]
Specified edge lengths on networkx/igraph (Python)
1,851,296
<p>I wanted to visualize a network with the data I have and would like to graph them with specific edge lengths. I use Python, and I've tried networkx and igraph to plot but all seem to assign fixed edge lengths. </p> <p>a.) I wonder if I did the codes wrong or the packages aren't really capable. How do you properly i...
5
2009-12-05T06:06:49Z
1,898,456
<p>This should work:</p> <pre><code>import networkx as NX import pygraphviz as PG G = PG.AGraph() nlist = "A B C D E".split() a, b = "A A B", "B C D" elist = zip(a.split(), b.split()) G.add_nodes_from(nlist) G.add_edges_from(elist) G.node_attr.update(color="red", style="filled") G.edge_attr.update(color="blue", len=...
4
2009-12-14T01:09:11Z
[ "python", "graphviz", "networkx", "igraph" ]
Troubles installing PyQt4
1,851,321
<p>I'm following <a href="http://diotavelli.net/PyQtWiki/BuildPyQt4Windows" rel="nofollow">this</a> guide.</p> <ul> <li>Python is at C:\Python31</li> <li>PyQt4 is at C:\Python31\pyqt</li> <li>sip is at C:\Python31\sip</li> <li>Qt is at C:\Qt\4.6.0</li> </ul> <p>I followed the instructions on that guide, but when I tr...
0
2009-12-05T06:17:42Z
1,851,337
<p>There is pre-built version already, why you still need to build yourself?</p> <p><a href="http://www.riverbankcomputing.co.uk/static/Downloads/PyQt4/PyQt-Py3.1-gpl-4.6.2-2.exe" rel="nofollow">http://www.riverbankcomputing.co.uk/static/Downloads/PyQt4/PyQt-Py3.1-gpl-4.6.2-2.exe</a></p>
4
2009-12-05T06:23:34Z
[ "python", "pyqt4", "python-sip" ]
resampling, interpolating matrix
1,851,384
<p>I'm trying to interpolate some data for the purpose of plotting. For instance, given N data points, I'd like to be able to generate a "smooth" plot, made up of 10*N or so interpolated data points.</p> <p>My approach is to generate an N-by-10*N matrix and compute the inner product the original vector and the matrix ...
9
2009-12-05T06:46:55Z
1,851,402
<p>Small improvement. Use the built-in numpy.sinc(x) function which runs in compiled C code.</p> <p>Possible larger improvement: Can you do the interpolation on the fly (as the plotting occurs)? Or are you tied to a plotting library that only accepts a matrix?</p>
0
2009-12-05T06:55:06Z
[ "python", "matrix", "interpolation", "signal-processing", "generator" ]
resampling, interpolating matrix
1,851,384
<p>I'm trying to interpolate some data for the purpose of plotting. For instance, given N data points, I'd like to be able to generate a "smooth" plot, made up of 10*N or so interpolated data points.</p> <p>My approach is to generate an N-by-10*N matrix and compute the inner product the original vector and the matrix ...
9
2009-12-05T06:46:55Z
1,851,907
<p>Your question isn't entirely clear; you're trying to optimize the code you posted, right?</p> <p>Re-writing sinc like this should speed it up considerably. This implementation avoids checking that the math module is imported on every call, doesn't do attribute access three times, and replaces exception handling wit...
1
2009-12-05T11:10:08Z
[ "python", "matrix", "interpolation", "signal-processing", "generator" ]
resampling, interpolating matrix
1,851,384
<p>I'm trying to interpolate some data for the purpose of plotting. For instance, given N data points, I'd like to be able to generate a "smooth" plot, made up of 10*N or so interpolated data points.</p> <p>My approach is to generate an N-by-10*N matrix and compute the inner product the original vector and the matrix ...
9
2009-12-05T06:46:55Z
1,852,020
<p>If you want to interpolate data in a quite general and fast way, splines or polynomials are very useful. Scipy has the scipy.interpolate module, which is very useful. You can find <a href="http://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html" rel="nofollow">many examples</a> in the official pages.</...
2
2009-12-05T11:51:51Z
[ "python", "matrix", "interpolation", "signal-processing", "generator" ]
resampling, interpolating matrix
1,851,384
<p>I'm trying to interpolate some data for the purpose of plotting. For instance, given N data points, I'd like to be able to generate a "smooth" plot, made up of 10*N or so interpolated data points.</p> <p>My approach is to generate an N-by-10*N matrix and compute the inner product the original vector and the matrix ...
9
2009-12-05T06:46:55Z
1,852,766
<p>Here's a minimal example of 1d interpolation with scipy -- not as much fun as reinventing, but.<br> The plot looks like <code>sinc</code>, which is no coincidence: try google spline resample "approximate sinc".<br> (Presumably less local / more taps &rArr; better approximation, but I have no idea how local Univariat...
1
2009-12-05T17:10:34Z
[ "python", "matrix", "interpolation", "signal-processing", "generator" ]
resampling, interpolating matrix
1,851,384
<p>I'm trying to interpolate some data for the purpose of plotting. For instance, given N data points, I'd like to be able to generate a "smooth" plot, made up of 10*N or so interpolated data points.</p> <p>My approach is to generate an N-by-10*N matrix and compute the inner product the original vector and the matrix ...
9
2009-12-05T06:46:55Z
1,854,486
<p>I'm not quite sure what you're trying to do, but there are some speedups you can do to create the matrix. <a href="http://stackoverflow.com/questions/1851384/resampling-interpolating-matrix/1851402#1851402">Braincore's suggestion</a> to use <code>numpy.sinc</code> is a first step, but the second is to realize that ...
1
2009-12-06T05:57:16Z
[ "python", "matrix", "interpolation", "signal-processing", "generator" ]
resampling, interpolating matrix
1,851,384
<p>I'm trying to interpolate some data for the purpose of plotting. For instance, given N data points, I'd like to be able to generate a "smooth" plot, made up of 10*N or so interpolated data points.</p> <p>My approach is to generate an N-by-10*N matrix and compute the inner product the original vector and the matrix ...
9
2009-12-05T06:46:55Z
1,858,212
<p>If your only interest is to 'generate a "smooth" plot' I would just go with a simple polynomial spline curve fit:</p> <p>For any two adjacent data points the coefficients of a third degree polynomial function can be computed from the coordinates of those data points and the two additional points to their left and ...
1
2009-12-07T06:28:59Z
[ "python", "matrix", "interpolation", "signal-processing", "generator" ]
resampling, interpolating matrix
1,851,384
<p>I'm trying to interpolate some data for the purpose of plotting. For instance, given N data points, I'd like to be able to generate a "smooth" plot, made up of 10*N or so interpolated data points.</p> <p>My approach is to generate an N-by-10*N matrix and compute the inner product the original vector and the matrix ...
9
2009-12-05T06:46:55Z
1,858,249
<p>I recommend that you check your algorithm, as it is a non-trivial problem. Specifically, I suggest you gain access to the article "Function Plotting Using Conic Splines" (IEEE Computer Graphics and Applications) by Hu and Pavlidis (1991). Their algorithm implementation allows for adaptive sampling of the function, s...
0
2009-12-07T06:38:17Z
[ "python", "matrix", "interpolation", "signal-processing", "generator" ]
resampling, interpolating matrix
1,851,384
<p>I'm trying to interpolate some data for the purpose of plotting. For instance, given N data points, I'd like to be able to generate a "smooth" plot, made up of 10*N or so interpolated data points.</p> <p>My approach is to generate an N-by-10*N matrix and compute the inner product the original vector and the matrix ...
9
2009-12-05T06:46:55Z
7,493,607
<p>This is upsampling. See <a href="http://stackoverflow.com/questions/5156690/help-with-resampling-upsampling">Help with resampling/upsampling</a> for some example solutions.</p> <p>A fast way to do this (for offline data, like your plotting application) is to use FFTs. This is what SciPy's native <a href="http://d...
7
2011-09-21T01:28:08Z
[ "python", "matrix", "interpolation", "signal-processing", "generator" ]
Ruby Quiz for Python
1,851,396
<p>Is there a blog/forum/listserv that is equivalent to RubyQuiz.com for the Python language?</p>
2
2009-12-05T06:52:43Z
1,851,640
<p>How about the <a href="http://www.pythonchallenge.com/" rel="nofollow">Python Challenge</a>?</p> <p>It isn't a weekly challenge, more a fixed set of challenges of increasing difficulty but it is fun and educational none-the-less. A great way to get to know python and have fun solving puzzles. Try to do them yours...
2
2009-12-05T09:01:04Z
[ "python" ]
Ruby Quiz for Python
1,851,396
<p>Is there a blog/forum/listserv that is equivalent to RubyQuiz.com for the Python language?</p>
2
2009-12-05T06:52:43Z
1,852,706
<p>At the risk of stating the obvious, why not just do the rubyquiz examples in python. Those exercises as well as others aren't tied to a language - you're just as well off just doing projecteuler problems in python rather than searching for python-specific puzzles. A puzzle is a puzzle a language is just a tool to so...
1
2009-12-05T16:49:24Z
[ "python" ]
Get physical map location of object based off user input
1,851,722
<p>I am getting user input into a python application of a local landmark. With this data I am trying to get the longitude and latitude of their object using Google maps. I am trying to work with the Google gdata api for the maps but I did not find a way to get long and lat data from a search query when working in pyt...
1
2009-12-05T09:44:18Z
1,851,825
<p>You can use geopy (<a href="http://code.google.com/p/geopy/wiki/GettingStarted" rel="nofollow">http://code.google.com/p/geopy/wiki/GettingStarted</a>). It can query Google and several additional services.</p>
1
2009-12-05T10:33:47Z
[ "python", "google-maps", "gdata-api" ]
Get physical map location of object based off user input
1,851,722
<p>I am getting user input into a python application of a local landmark. With this data I am trying to get the longitude and latitude of their object using Google maps. I am trying to work with the Google gdata api for the maps but I did not find a way to get long and lat data from a search query when working in pyt...
1
2009-12-05T09:44:18Z
1,851,838
<p>Are you trying to geocode a street or POI (point of interest)? In that case, <a href="http://code.google.com/p/geopy">geopy</a> is perfect:</p> <pre><code>In [1]: from geopy import geocoders In [2]: g = geocoders.Google(GOOGLE_MAPS_API_KEY) In [3]: (place, point) = g.geocode('Eiffel Tower, Paris') Fetching http:/...
5
2009-12-05T10:38:14Z
[ "python", "google-maps", "gdata-api" ]
Get physical map location of object based off user input
1,851,722
<p>I am getting user input into a python application of a local landmark. With this data I am trying to get the longitude and latitude of their object using Google maps. I am trying to work with the Google gdata api for the maps but I did not find a way to get long and lat data from a search query when working in pyt...
1
2009-12-05T09:44:18Z
1,959,681
<p>I have a JQuery Plugin that will allow you to plot multiple addresses from a json object. In my demo, I load the json object from a php file, so I'm sure that you can do the same with python.</p> <p><a href="http://grasshopperpebbles.com/ajax/jquery-plugin-imgooglemaps-0-9-multiple-addresses-street-view/" rel="nofo...
0
2009-12-24T20:32:49Z
[ "python", "google-maps", "gdata-api" ]
Scaling an image to its parent button size in GTK?
1,851,862
<p>I have a GTK layout with a widget on the left of an HBox deciding the maximum height I want, and a VBox on the right containing three buttons, each containing only an image and no text. The images are a GTK stock icon, and so have the stock storage type.</p> <p>Using expand=True, fill=True packing the buttons witho...
2
2009-12-05T10:48:24Z
1,872,356
<p>There's no way to automatically do you want you want. You might want to subclass gtk.Image and in your subclass, scale a pixbuf to your widget's allocation size. The advantage of this is that you'll have a reusable widget and you'll be able to have it resize your image on the fly.</p> <p>The downside is that you'll...
2
2009-12-09T08:10:48Z
[ "python", "user-interface", "pygtk", "gtk" ]
Scaling an image to its parent button size in GTK?
1,851,862
<p>I have a GTK layout with a widget on the left of an HBox deciding the maximum height I want, and a VBox on the right containing three buttons, each containing only an image and no text. The images are a GTK stock icon, and so have the stock storage type.</p> <p>Using expand=True, fill=True packing the buttons witho...
2
2009-12-05T10:48:24Z
1,894,869
<p>I've been having luck using SVG files and scaling them since it's easy to incorporate SVG in pyGtk programs. </p> <pre><code>img = gtk.gdk.pixbuf_new_from_file(fname) </code></pre> <p>What I do is copy the svg to a temporary file and modify the first ' <p>Then I read i that modified svg and it'll load as a pixbuf...
1
2009-12-12T22:17:04Z
[ "python", "user-interface", "pygtk", "gtk" ]
No output from QProcess
1,851,930
<p>Why does the following print a blank line instead of 'Hello QProcess'?</p> <pre><code>import sys from PyQt4 import QtGui, QtCore proc = QtCore.QProcess() proc.start("echo 'Hello QProcess'") proc.waitForFinished() result = proc.readAll() print result proc.close() </code></pre> <p>I'm on Windows XP, btw.</p>
0
2009-12-05T11:20:24Z
1,852,205
<p>Because there's no program called "echo".</p> <p>If you wanted to run this through the shell then you should have used "cmd /C echo Hello QProcess".</p> <p>Your program also has no error checking. If you'd checked for errors properly the mistake would have been easier to spot.</p>
2
2009-12-05T13:31:52Z
[ "python", "windows", "qt", "pyqt", "qprocess" ]
No output from QProcess
1,851,930
<p>Why does the following print a blank line instead of 'Hello QProcess'?</p> <pre><code>import sys from PyQt4 import QtGui, QtCore proc = QtCore.QProcess() proc.start("echo 'Hello QProcess'") proc.waitForFinished() result = proc.readAll() print result proc.close() </code></pre> <p>I'm on Windows XP, btw.</p>
0
2009-12-05T11:20:24Z
6,258,420
<p>You should provide system environment to your proc.</p> <pre><code>proc.setEnvironment(QProcess::systemEnvironment()); </code></pre> <p>echo is exceptional command in Windows that does not have executable.</p>
0
2011-06-06T21:47:55Z
[ "python", "windows", "qt", "pyqt", "qprocess" ]
Lua equivalent to shlex?
1,851,940
<p>Is there a Lua equivalent for python's <a href="http://docs.python.org/lib/module-shlex.html">shlex</a> library?</p>
6
2009-12-05T11:24:50Z
1,852,117
<p>I found a reference to a project called <a href="http://luaparse.luaforge.net/" rel="nofollow">LuaParse</a>:</p> <blockquote> <p>LuaParse includes Blex, a general purpose pure-Lua lexer, and lparse, a pure-Lua Lua parser, as well as a variety of utility functions and a prototype package management system.</p> </b...
3
2009-12-05T12:46:08Z
[ "python", "parsing", "lua", "command-line-arguments" ]
Lua equivalent to shlex?
1,851,940
<p>Is there a Lua equivalent for python's <a href="http://docs.python.org/lib/module-shlex.html">shlex</a> library?</p>
6
2009-12-05T11:24:50Z
1,853,465
<p>See also <a href="http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html" rel="nofollow">LPeg</a>.</p>
4
2009-12-05T21:03:31Z
[ "python", "parsing", "lua", "command-line-arguments" ]
Lua equivalent to shlex?
1,851,940
<p>Is there a Lua equivalent for python's <a href="http://docs.python.org/lib/module-shlex.html">shlex</a> library?</p>
6
2009-12-05T11:24:50Z
1,853,626
<p>See also <code>gg</code>, <code>mlp</code> and <code>clopts</code> modules from <a href="http://metalua.luaforge.net/manual000.html" rel="nofollow">Metalua</a>.</p> <p>Those are 'not-quite' Lua (as Metalua is a separate language), but may provide some useful insights. Also Metalua code compiles into plain Lua bytec...
1
2009-12-05T22:08:17Z
[ "python", "parsing", "lua", "command-line-arguments" ]
Lua equivalent to shlex?
1,851,940
<p>Is there a Lua equivalent for python's <a href="http://docs.python.org/lib/module-shlex.html">shlex</a> library?</p>
6
2009-12-05T11:24:50Z
1,863,009
<p>If the goal is to parse a shell-like language (which appears to be shlex's actual design goal) then writing a grammar in <a href="http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html" rel="nofollow">LPeg</a> as <a href="http://stackoverflow.com/questions/1851940/lua-equivalent-to-shlex/1853465#1853465">lhf suggests</a>...
3
2009-12-07T21:26:44Z
[ "python", "parsing", "lua", "command-line-arguments" ]
Why is pdb displaying "*** Blank or comment" when I try to set a Break?
1,852,427
<p>I'm working with my Django app. For some reason an element of a list is being assigned incorrectly.</p> <p>I'm trying to set a break where I think the error is occurring. ( line 20 )</p> <p>I'm invoking pdb with this line of code: </p> <pre><code>import pdb; pdb.set_trace() </code></pre> <p>However, inside the ...
4
2009-12-05T15:05:20Z
1,852,440
<p>pdb is telling you that line 20 of the file you're in doesn't contain code; it's either blank or just contains a comment. Such a line will never actually be executed, so a breakpoint can't be set on it.</p> <p>Use the 'list' command to see the code of the file you're currently in ('help list' for details on this co...
3
2009-12-05T15:11:42Z
[ "python", "django", "pdb" ]
Django application deployment help
1,852,693
<p>I'm using Capistrano to deploy a Django application (it uses Nginx as the web server), using instructions I found at <a href="http://akashxav.com/2009/07/11/getting-django-running-on-nginx-and-fastcgi-on-prgmr/" rel="nofollow">http://akashxav.com/2009/07/11/getting-django-running-on-nginx-and-fastcgi-on-prgmr/</a> (...
1
2009-12-05T16:45:49Z
1,852,969
<p>There is a <a href="https://docs.djangoproject.com/en/1.8/howto/deployment/fastcgi/#stopping-the-fastcgi-daemon" rel="nofollow">section in the django docs about this</a></p> <p>Basically use the pidfile option to manage.py and then write a small shell script to use that pid to kill the existing cgi process if it ex...
1
2009-12-05T18:12:33Z
[ "python", "django", "deployment" ]
Python values with units
1,852,720
<p>I need to keep track of units on float and int values in Python, but I don't want to use an external package like magnitude or others, because I don't need to perform operations on the values. Instead, all I want is to be able to define floats and ints that have a unit attribute (and I don't want to add a new depend...
3
2009-12-05T16:54:13Z
1,852,730
<p>It looks like you need to check if kwargs is not None before you try to see if there is a label 'unit'.</p> <p>Change your code to</p> <pre><code> if kwargs and 'unit' in kwargs: </code></pre> <p>Updated answer:</p> <pre><code>don't pass kwargs to __oldinit__ </code></pre>
-2
2009-12-05T16:58:32Z
[ "python" ]
Python values with units
1,852,720
<p>I need to keep track of units on float and int values in Python, but I don't want to use an external package like magnitude or others, because I don't need to perform operations on the values. Instead, all I want is to be able to define floats and ints that have a unit attribute (and I don't want to add a new depend...
3
2009-12-05T16:54:13Z
1,852,733
<p>I think you mean</p> <pre><code>class floatwithunit(float): </code></pre> <p>rather than</p> <pre><code>def floatwithunit(float): </code></pre>
1
2009-12-05T16:58:51Z
[ "python" ]
Python values with units
1,852,720
<p>I need to keep track of units on float and int values in Python, but I don't want to use an external package like magnitude or others, because I don't need to perform operations on the values. Instead, all I want is to be able to define floats and ints that have a unit attribute (and I don't want to add a new depend...
3
2009-12-05T16:54:13Z
1,852,762
<p>You need to override <code>__new__</code> (the "constructor proper", while <code>__init__</code> is the "initializer"), otherwise <code>float</code>'s <code>__new__</code> gets called with extraneous arguments, which is the cause of the problem you're seeing. You don't need to call float's <code>__init__</code> (it...
6
2009-12-05T17:09:51Z
[ "python" ]
Python values with units
1,852,720
<p>I need to keep track of units on float and int values in Python, but I don't want to use an external package like magnitude or others, because I don't need to perform operations on the values. Instead, all I want is to be able to define floats and ints that have a unit attribute (and I don't want to add a new depend...
3
2009-12-05T16:54:13Z
1,852,777
<p>You might be looking for something like this:</p> <pre><code>class UnitFloat(float): def __new__(self, value, unit=None): return float.__new__(self, value) def __init__(self, value, unit=None): self.unit = unit x = UnitFloat(35.5, "cm") y = UnitFloat(42.5) print x print x.unit print y p...
8
2009-12-05T17:14:01Z
[ "python" ]
Python values with units
1,852,720
<p>I need to keep track of units on float and int values in Python, but I don't want to use an external package like magnitude or others, because I don't need to perform operations on the values. Instead, all I want is to be able to define floats and ints that have a unit attribute (and I don't want to add a new depend...
3
2009-12-05T16:54:13Z
1,852,799
<p>Alex Martelli indeed pointed out the root of the problem. I always find __new__ quite confusing, however, so here's a working piece of example code:</p> <pre><code>class FloatWithUnit(float): def __new__(cls, *args, **kwargs): # avoid error in float.__new__ # the original kwargs (with 'unit') wi...
0
2009-12-05T17:24:47Z
[ "python" ]
Python raw_input into dictionary declared in a class
1,853,093
<p>I am incredibly new to Python and I really need to be able to work this out. I want to be asking the user via raw_input what the module and grade is and then putting this into the dictionary already defined in the Student class as grades. I've got no idea what to do! Thanks in advance!</p> <pre><code>students = [] ...
0
2009-12-05T18:59:31Z
1,853,278
<p>A few things:</p> <ol> <li><p>Move the initialization of your class attributes into an <code>__init__</code> method:</p></li> <li><p>Get rid of all the getters and setters as Jeffrey says. </p></li> <li><p>Use a dict that has module names as keys and grades as values:</p></li> </ol> <p>Some code snippets:</p> <p...
2
2009-12-05T20:02:38Z
[ "python", "variables", "dictionary", "class" ]
What are my options (if any) for MySQL with Python 3?
1,853,202
<p>I recently starting playing around with the new features of Python 3.1 and porting one of my 2.6 apps. I was surprised to find that MySQLdb does not yet support any of the 3.x versions of Python. My app uses MySQL extensively, so, as you can imagine, I didn't get too far!</p> <p>What are my options (if any) for w...
8
2009-12-05T19:35:52Z
1,853,404
<p><a href="http://sourceforge.net/projects/mypysql/" rel="nofollow">mypysql</a> doesn't follow the Python DB API standard, but does support Mysql and Python 3.</p>
4
2009-12-05T20:46:25Z
[ "python", "mysql" ]
What are my options (if any) for MySQL with Python 3?
1,853,202
<p>I recently starting playing around with the new features of Python 3.1 and porting one of my 2.6 apps. I was surprised to find that MySQLdb does not yet support any of the 3.x versions of Python. My app uses MySQL extensively, so, as you can imagine, I didn't get too far!</p> <p>What are my options (if any) for w...
8
2009-12-05T19:35:52Z
36,298,606
<p>You could use <code>pymysql</code>. "The goal of PyMySQL is to be a drop-in replacement for MySQLdb". Check the docs <a href="https://github.com/PyMySQL/PyMySQL" rel="nofollow">here</a>. </p> <blockquote> <p>pip install mysqlclient pymysql</p> </blockquote> <p>Once these libraries are installed, just add the lin...
0
2016-03-30T02:31:05Z
[ "python", "mysql" ]
Writing a Faster Python Spider
1,853,673
<p>I'm writing a spider in Python to crawl a site. Trouble is, I need to examine about 2.5 million pages, so I could really use some help making it optimized for speed.</p> <p>What I need to do is examine the pages for a certain number, and if it is found to record the link to the page. The spider is very simple, it j...
6
2009-12-05T22:28:40Z
1,853,687
<p>You could use <a href="http://en.wikipedia.org/wiki/MapReduce">MapReduce</a> like Google does, either via <a href="http://hadoop.apache.org/">Hadoop</a> (specifically with Python: <a href="http://www.michael-noll.com/wiki/Writing%5FAn%5FHadoop%5FMapReduce%5FProgram%5FIn%5FPython">1</a> and <a href="http://blog.last....
9
2009-12-05T22:34:33Z
[ "python", "web-crawler" ]
Writing a Faster Python Spider
1,853,673
<p>I'm writing a spider in Python to crawl a site. Trouble is, I need to examine about 2.5 million pages, so I could really use some help making it optimized for speed.</p> <p>What I need to do is examine the pages for a certain number, and if it is found to record the link to the page. The spider is very simple, it j...
6
2009-12-05T22:28:40Z
1,853,689
<p>Spidering somebody's site with millions of requests isn't very polite. Can you instead ask the webmaster for an archive of the site? Once you have that, it's a simple matter of text searching.</p>
3
2009-12-05T22:34:37Z
[ "python", "web-crawler" ]
Writing a Faster Python Spider
1,853,673
<p>I'm writing a spider in Python to crawl a site. Trouble is, I need to examine about 2.5 million pages, so I could really use some help making it optimized for speed.</p> <p>What I need to do is examine the pages for a certain number, and if it is found to record the link to the page. The spider is very simple, it j...
6
2009-12-05T22:28:40Z
1,853,842
<p>Where are you storing the results? You can use <a href="http://www.picloud.com">PiCloud</a>'s cloud library to parallelize your scraping easily across a cluster of servers.</p>
5
2009-12-05T23:27:27Z
[ "python", "web-crawler" ]
Writing a Faster Python Spider
1,853,673
<p>I'm writing a spider in Python to crawl a site. Trouble is, I need to examine about 2.5 million pages, so I could really use some help making it optimized for speed.</p> <p>What I need to do is examine the pages for a certain number, and if it is found to record the link to the page. The spider is very simple, it j...
6
2009-12-05T22:28:40Z
1,853,865
<p>You waste a lot of time waiting for network requests when spidering, so you'll definitely want to make your requests in parallel. I would probably save the result data to disk and then have a second process looping over the files searching for the term. That phase could easily be distributed across multiple machin...
3
2009-12-05T23:35:06Z
[ "python", "web-crawler" ]
Writing a Faster Python Spider
1,853,673
<p>I'm writing a spider in Python to crawl a site. Trouble is, I need to examine about 2.5 million pages, so I could really use some help making it optimized for speed.</p> <p>What I need to do is examine the pages for a certain number, and if it is found to record the link to the page. The spider is very simple, it j...
6
2009-12-05T22:28:40Z
1,854,545
<p>As you are new to Python, I think the following may be helpful for you :)</p> <ul> <li>if you are writing regex to search for certain pattern in the page, compile your regex wherever you can and reuse the compiled object</li> <li><a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a> is a html/xm...
5
2009-12-06T06:27:12Z
[ "python", "web-crawler" ]
Writing a Faster Python Spider
1,853,673
<p>I'm writing a spider in Python to crawl a site. Trouble is, I need to examine about 2.5 million pages, so I could really use some help making it optimized for speed.</p> <p>What I need to do is examine the pages for a certain number, and if it is found to record the link to the page. The spider is very simple, it j...
6
2009-12-05T22:28:40Z
1,854,592
<p>What Adam said. I did this once to map out Xanga's network. The way I made it faster is by having a thread-safe set containing all usernames I had to look up. Then I had 5 or so threads making requests at the same time and processing them. You're going to spend way more time waiting for the page to DL than you will ...
0
2009-12-06T06:55:06Z
[ "python", "web-crawler" ]
Python networkx 2D radial plotting
1,853,892
<p>How do you make a graph in networkx such that its layout is 2D, radial, and the edges are plotted in increasing edge lengths or weights?</p>
0
2009-12-05T23:44:31Z
1,855,293
<p>Have you tried asking your question on the <a href="http://groups.google.com/group/networkx-discuss" rel="nofollow">mailing list</a>?</p>
0
2009-12-06T12:40:02Z
[ "python", "2d", "networkx", "weight", "radial" ]
Replace Multiple lines in Jython
1,853,921
<p>I have written a small program to replace a set of characters , but i also want two or more replace command in a single program . </p> <p>Apart from it i also want to add an bracket after random set of characters.</p> <p>This is my Program </p> <pre><code>file_read=open('&lt;%=odiRef.getOption("READ")%&gt;/EXPORT...
0
2009-12-05T23:50:17Z
1,854,845
<p>This is wrong on many levels - you can not simultaneously read and write from the same file, file.read() command reads entire contents, and you dont have to save after each replace. Something like this:</p> <pre><code>file = open('myfile', 'r+') contents = file.read() file.seek(0) # rewind file.write(contents.r...
3
2009-12-06T09:14:11Z
[ "python", "string", "replace", "jython" ]
Python web application
1,854,058
<p>I want to create a very simple python web app. I don't need Django or any other web framwwork like that. Isn't there a simpler way to create a web app in python?</p> <p>Thanks</p>
5
2009-12-06T00:39:21Z
1,854,067
<p><a href="http://en.wikipedia.org/wiki/Web%5FServer%5FGateway%5FInterface" rel="nofollow">WSGI</a> is probably what you are looking for. Though there are several lightweight python <a href="http://wiki.python.org/moin/WebFrameworks" rel="nofollow">web frameworks</a> around which are less monolithic than django.</p>
3
2009-12-06T00:42:11Z
[ "python" ]
Python web application
1,854,058
<p>I want to create a very simple python web app. I don't need Django or any other web framwwork like that. Isn't there a simpler way to create a web app in python?</p> <p>Thanks</p>
5
2009-12-06T00:39:21Z
1,854,078
<p>Sure! <a href="http://code.google.com/appengine/docs/python/gettingstarted/helloworld.html" rel="nofollow">For example</a>, </p> <pre><code>print 'Content-Type: text/plain' print '' print 'Hello, world!' </code></pre> <p>this is a web app -- if you save it into a file in an appropriate directory of a machine runn...
5
2009-12-06T00:47:27Z
[ "python" ]
Python web application
1,854,058
<p>I want to create a very simple python web app. I don't need Django or any other web framwwork like that. Isn't there a simpler way to create a web app in python?</p> <p>Thanks</p>
5
2009-12-06T00:39:21Z
1,854,079
<p>If you don't need Django, try web.py</p> <p><a href="http://webpy.org/">http://webpy.org/</a></p> <pre><code>import web urls = ( '/(.*)', 'hello' ) app = web.application(urls, globals()) class hello: def GET(self, name): if not name: name = 'world' return 'Hello, ' + ...
10
2009-12-06T00:47:56Z
[ "python" ]
Python web application
1,854,058
<p>I want to create a very simple python web app. I don't need Django or any other web framwwork like that. Isn't there a simpler way to create a web app in python?</p> <p>Thanks</p>
5
2009-12-06T00:39:21Z
1,854,084
<p>The truth is that you do need a framework of some sort even if it's extremely minimal. You can use WSGI as a base and at least you're doing a little better. Python is a very powerful, very unspecific programming language so if you decide to do it without a framework you're going to have to rewrite huge amounts of co...
1
2009-12-06T00:48:26Z
[ "python" ]
Python web application
1,854,058
<p>I want to create a very simple python web app. I don't need Django or any other web framwwork like that. Isn't there a simpler way to create a web app in python?</p> <p>Thanks</p>
5
2009-12-06T00:39:21Z
1,855,919
<p>Yep WSGI...</p> <pre><code>def hello_wsgi(environ, start_response): start_response('200 OK', [('content-type', 'text/html')]) return ['Hello world!'] </code></pre> <p>If you want to abstract this in terms of request/response to get a little further away from http try <a href="http://pythonpaste.org/webob/"...
0
2009-12-06T17:17:39Z
[ "python" ]
Python web application
1,854,058
<p>I want to create a very simple python web app. I don't need Django or any other web framwwork like that. Isn't there a simpler way to create a web app in python?</p> <p>Thanks</p>
5
2009-12-06T00:39:21Z
7,938,024
<p>I use <a href="http://bottlepy.org" rel="nofollow">bottle</a> all the time as a minimal web framework. It is very simple to use.</p> <p>as a minimum example - taken from the web site :</p> <pre><code>from bottle import route, run @route('/hello/:name') def index(name='World'): return '&lt;b&gt;Hello %s!&lt;/b...
0
2011-10-29T09:26:26Z
[ "python" ]
Python web application
1,854,058
<p>I want to create a very simple python web app. I don't need Django or any other web framwwork like that. Isn't there a simpler way to create a web app in python?</p> <p>Thanks</p>
5
2009-12-06T00:39:21Z
24,857,190
<p>Now a days it is better to use PhusionPassenger Standalone or with NGINX using same technique as PHP by proxy passing it to FastCGI in case of PHP and WSGI for Python.</p> <p>The URL and all explanation for Passenger can be found: <a href="http://www.phusionpassenger.com" rel="nofollow">Here</a></p> <p>All informa...
0
2014-07-21T03:10:32Z
[ "python" ]
Python web application
1,854,058
<p>I want to create a very simple python web app. I don't need Django or any other web framwwork like that. Isn't there a simpler way to create a web app in python?</p> <p>Thanks</p>
5
2009-12-06T00:39:21Z
28,221,317
<p>You can try Appier (<a href="https://github.com/hivesolutions/appier" rel="nofollow">https://github.com/hivesolutions/appier</a>). Here's a sample app:</p> <pre><code>import appier class HelloApp(appier.App): @appier.route("/", "GET") def hello(self): return "Hello World" HelloApp().serve() </cod...
0
2015-01-29T17:52:03Z
[ "python" ]
Raise unhandled exceptions in a thread in the main thread?
1,854,216
<p>There are some similar questions, but none supply the answer I require.</p> <p>If I create threads via <code>threading.Thread</code>, which then throw exceptions which are unhandled, those threads are terminated. I wish to retain the default print out of the exception details with the stack trace, but bring down th...
10
2009-12-06T03:05:50Z
1,854,263
<p>I wrote about <a href="http://nedbatchelder.com/blog/200711/rethrowing%5Fexceptions%5Fin%5Fpython.html">Re-throwing exceptions in Python</a>, including something very much like this as an example.</p> <p>On your worker thread you do this:</p> <pre><code>try: self.result = self.do_something_dangerous() except E...
9
2009-12-06T03:39:43Z
[ "python", "exception-handling", "multithreading", "systemexit" ]
Raise unhandled exceptions in a thread in the main thread?
1,854,216
<p>There are some similar questions, but none supply the answer I require.</p> <p>If I create threads via <code>threading.Thread</code>, which then throw exceptions which are unhandled, those threads are terminated. I wish to retain the default print out of the exception details with the stack trace, but bring down th...
10
2009-12-06T03:05:50Z
1,856,364
<p>The only exception a secondary thread can reliably raise in the main thread is <code>KeyboardInterrupt</code>: the way the secondary thread does it is by calling the function <a href="http://docs.python.org/library/thread.html?highlight=thread%20main#thread.interrupt%5Fmain"><code>thread.interrupt_main()</code></a>....
5
2009-12-06T19:39:40Z
[ "python", "exception-handling", "multithreading", "systemexit" ]
Raise unhandled exceptions in a thread in the main thread?
1,854,216
<p>There are some similar questions, but none supply the answer I require.</p> <p>If I create threads via <code>threading.Thread</code>, which then throw exceptions which are unhandled, those threads are terminated. I wish to retain the default print out of the exception details with the stack trace, but bring down th...
10
2009-12-06T03:05:50Z
29,455,811
<p>Very unfortunately the accepted answer does not answer the question. You would rather pipe the exception details into a Queue. Please have a look at: <a href="http://stackoverflow.com/questions/2829329/catch-a-threads-exception-in-the-caller-thread-in-python" title="Catch a thread&#39;s exception in the caller threa...
0
2015-04-05T09:14:38Z
[ "python", "exception-handling", "multithreading", "systemexit" ]
Django edit form based on add form?
1,854,237
<p>I've made a nice form, and a big complicated 'add' function for handling it. It starts like this...</p> <pre><code>def add(req): if req.method == 'POST': form = ArticleForm(req.POST) if form.is_valid(): article = form.save(commit=False) article.author = req.user ...
30
2009-12-06T03:18:48Z
1,854,401
<p>You can have hidden ID field in form and for edit form it will be passed with the form for add form you can set it in req.POST e.g. </p> <pre><code>formData = req.POST.copy() formData['id'] = getNewID() </code></pre> <p>and pass that formData to form</p>
1
2009-12-06T04:52:36Z
[ "python", "django", "forms", "logic" ]
Django edit form based on add form?
1,854,237
<p>I've made a nice form, and a big complicated 'add' function for handling it. It starts like this...</p> <pre><code>def add(req): if req.method == 'POST': form = ArticleForm(req.POST) if form.is_valid(): article = form.save(commit=False) article.author = req.user ...
30
2009-12-06T03:18:48Z
1,854,453
<p>If you are extending your form from a ModelForm, use the <code>instance</code> keyword argument. Here we pass either an existing <code>instance</code> or a new one, depending on whether we're editing or adding an existing article. In both cases the <code>author</code> field is set on the instance, so <code>commit=Fa...
73
2009-12-06T05:27:24Z
[ "python", "django", "forms", "logic" ]
No readyReadStandardOutput signal from QProcess
1,854,247
<p>Why do I never get the readyReadStandardOutput signal when I run the following?</p> <pre><code>import os, sys, textwrap from PyQt4 import QtGui, QtCore out_file = open("sleep_loop.py", 'w') out_file.write(textwrap.dedent(""" import time while True: print "sleeping..." time.sleep(1)""")) o...
1
2009-12-06T03:24:44Z
1,854,666
<p>Two problems here:</p> <ol> <li>You should create QApplication instance before creating everything else.</li> <li>Your child process is buffering its output.</li> </ol> <p>Here is the fixed code, only two lines changed:</p> <ol> <li><code>app = QApplication</code> moved before <code>proc = QProcess</code></li> <l...
3
2009-12-06T07:40:12Z
[ "python", "qt", "pyqt", "qprocess" ]
how stackless python can be fast for concurrency?
1,854,278
<p>stackless python didn't take a good usage of multi-core, so where is the point it should be faster than python thread/multiprocessing ?</p> <p>all the benchmark use stackless python tasklet to compare with python thread lock and queue, that's unfair, cause lock always has low efficiency </p> <p>see, if use single...
2
2009-12-06T03:48:23Z
1,854,333
<p><em>Focus on functionality first, and performance second (unless you know you have the need).</em> </p> <p>Most of the time on a server is spent with I/O, so multi-cores do not help so much. If it is <strong>mostly</strong> I/O that you are working with, multi-threading python may be the simplest answer. </p> <...
2
2009-12-06T04:17:41Z
[ "python", "concurrency", "stackless", "python-stackless" ]
how stackless python can be fast for concurrency?
1,854,278
<p>stackless python didn't take a good usage of multi-core, so where is the point it should be faster than python thread/multiprocessing ?</p> <p>all the benchmark use stackless python tasklet to compare with python thread lock and queue, that's unfair, cause lock always has low efficiency </p> <p>see, if use single...
2
2009-12-06T03:48:23Z
4,222,704
<p>There is this new and trendy thing called asynchronous-IO-loops and message-passing-concurrency and a few other trendy terms. Well, its not at all new, but it is only just these last 5 years being discovered by the mainstream.</p> <p>Stackless Python is a version of Python where the VM has itself been modified to ...
0
2010-11-19T06:39:24Z
[ "python", "concurrency", "stackless", "python-stackless" ]
Google Federated Login vs Hybrid Protocol vs Google Data Authentication. Whats's the Difference?
1,854,467
<p>I am trying to implement Google Authentication in my website, in which I would also be pulling some Google Data using the Google Data API and I am using Google App Engine with Jinja2.</p> <p>My question is, so many ways are mentioned to do it. I am confused between Google Federated Login,Google Data Protocol, Hybri...
2
2009-12-06T05:41:10Z
2,542,757
<p>Here is an article specifically on <a href="http://code.google.com/appengine/articles/gdata.html" rel="nofollow">Retrieving Authenticated Google Data Feeds with Google App Engine</a></p> <p>The way I understand this example: </p> <ul> <li>You use the <a href="http://code.google.com/p/gdata-python-client/" rel="nof...
1
2010-03-30T03:45:13Z
[ "python", "openid", "oauth", "google-data" ]