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 |
|---|---|---|---|---|---|---|---|---|---|
Searching a website | 2,297,787 | <pre><code>import urllib
import re
import os
search = (raw_input('[!]Search: '))
site = "http://www.exploit-db.com/list.php?description="+search+"&author=&platform=&type=&port=&osvdb=&cve="
print site
source = urllib.urlopen(site).read()
founds = re.findall("href='/exploits/\d+",source)
print... | 0 | 2010-02-19T16:18:48Z | 2,297,851 | <p>Apparently the exploit-db.com site doesn't allow extending the page size. You therefore need to "manually" page through the result list by repeating the urllib.urlopen() to get subsequent pages. The URL is the same as the one initially used, plus the <code>&page=n</code> parameter. Attention this n value appe... | 0 | 2010-02-19T16:27:19Z | [
"python",
"urllib"
] |
Python using derived class's method in parent class? | 2,297,843 | <p>Can I force a parent class to call a derived class's version of a function?</p>
<pre><code>class Base(object):
attr1 = ''
attr2 = ''
def virtual(self):
pass # doesn't do anything in the parent class
def func(self):
print "%s, %s" % (self.attr1, self.attr2)
sel... | 7 | 2010-02-19T16:25:38Z | 2,297,875 | <p>If you instantiate a <code>Derived</code> (say <code>d = Derived()</code>), the <code>.virtual</code> that's called by <code>d.func()</code> <strong>is</strong> <code>Derived.virtual</code>. If there is no instance of <code>Derived</code> involved, then there's no suitable <code>self</code> for <code>Derived.virtua... | 8 | 2010-02-19T16:29:07Z | [
"python",
"inheritance",
"new-style-class"
] |
Python using derived class's method in parent class? | 2,297,843 | <p>Can I force a parent class to call a derived class's version of a function?</p>
<pre><code>class Base(object):
attr1 = ''
attr2 = ''
def virtual(self):
pass # doesn't do anything in the parent class
def func(self):
print "%s, %s" % (self.attr1, self.attr2)
sel... | 7 | 2010-02-19T16:25:38Z | 2,298,030 | <p>Ok, I just ended up passing the instance of virtual() I needed to func()</p>
<pre><code>class Base(object):
attr1 = ''
attr2 = ''
def __init__(self):
pass
def virtual(self):
pass
def func(self, cb):
print "%s, %s" % (self.attr1, self.attr2)
cb()
class Derive... | -1 | 2010-02-19T16:48:22Z | [
"python",
"inheritance",
"new-style-class"
] |
Python using derived class's method in parent class? | 2,297,843 | <p>Can I force a parent class to call a derived class's version of a function?</p>
<pre><code>class Base(object):
attr1 = ''
attr2 = ''
def virtual(self):
pass # doesn't do anything in the parent class
def func(self):
print "%s, %s" % (self.attr1, self.attr2)
sel... | 7 | 2010-02-19T16:25:38Z | 3,134,330 | <p>It isn't impossible -- there is a way around this actually, and you don't have to pass in the function or anything like that. I am working on a project myself where this exact problem came up. Here is the solution:</p>
<pre><code>
class Base(): # no need to explicitly derive object for it to work
attr1 = 'I am ... | 2 | 2010-06-28T16:43:50Z | [
"python",
"inheritance",
"new-style-class"
] |
Scripting language for trading strategy development | 2,297,889 | <p>I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles ... | 15 | 2010-02-19T16:31:00Z | 2,297,992 | <p>Custom-made modules are going to be needed, no matter what you choose, that define your firm's high level constructs. </p>
<p>Here are some of the needs I envision -- you may have some of these covered already: a way to get current positions, current and historical quotes, previous performance data, etc... into th... | 1 | 2010-02-19T16:42:46Z | [
"python",
"ruby",
"scripting",
"dsl",
"trading"
] |
Scripting language for trading strategy development | 2,297,889 | <p>I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles ... | 15 | 2010-02-19T16:31:00Z | 2,297,994 | <p>It sounds like you might need to create some sort of Domain Specific Language (DSL) for your users that could be built loosely on top of the target language. Ruby, Python and Lua all have their various quirks regarding syntax, and to a degree some of these can be massaged with clever function definitions.</p>
<p>An... | 8 | 2010-02-19T16:43:01Z | [
"python",
"ruby",
"scripting",
"dsl",
"trading"
] |
Scripting language for trading strategy development | 2,297,889 | <p>I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles ... | 15 | 2010-02-19T16:31:00Z | 2,298,008 | <p>This might be a bit simplistic, but a lot of quant users are used to working with Excel & VBA macros. Would something like VBSCript be usable, as they may have some experience in this area.</p>
| 0 | 2010-02-19T16:45:00Z | [
"python",
"ruby",
"scripting",
"dsl",
"trading"
] |
Scripting language for trading strategy development | 2,297,889 | <p>I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles ... | 15 | 2010-02-19T16:31:00Z | 2,298,038 | <p>Existing languages are "a little "low level" for my target users."</p>
<p>Yet, all you need is "a minimum of support for looping, simple arithmatic, logical expression evaluation"</p>
<p>I don't get the problem. You only want a few features. What's wrong with the list of languages you provided? They actually of... | 0 | 2010-02-19T16:49:00Z | [
"python",
"ruby",
"scripting",
"dsl",
"trading"
] |
Scripting language for trading strategy development | 2,297,889 | <p>I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles ... | 15 | 2010-02-19T16:31:00Z | 2,298,064 | <p>Mark-Jason Dominus, the author of Perl's <a href="http://search.cpan.org/perldoc?Text%3a%3aTemplate">Text::Template</a> module, has some insights that might be relevant:</p>
<blockquote>
<p>When people make a template module
like this one, they almost always
start by inventing a special syntax
for substitut... | 10 | 2010-02-19T16:51:50Z | [
"python",
"ruby",
"scripting",
"dsl",
"trading"
] |
Scripting language for trading strategy development | 2,297,889 | <p>I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles ... | 15 | 2010-02-19T16:31:00Z | 2,298,183 | <p>I would use Common Lisp, which supports rapid development (you have a running image and can compile/recompile individual functions) and tailoring the language to your domain. You would provide functions and macros as building blocks to express strategies, and the whole language would be available to the user for co... | 0 | 2010-02-19T17:09:42Z | [
"python",
"ruby",
"scripting",
"dsl",
"trading"
] |
Scripting language for trading strategy development | 2,297,889 | <p>I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles ... | 15 | 2010-02-19T16:31:00Z | 2,298,573 | <p>Define the language first -- if possible, use the pseudo-language called EBN, it's very simple (see the Wikipedia entry).</p>
<p>Then once you have that, pick the language. Almost certainly you will want to use a DSL. Ruby and Lua are both really good at that, IMO.</p>
<p>Once you start working on it, you may fi... | 0 | 2010-02-19T18:12:27Z | [
"python",
"ruby",
"scripting",
"dsl",
"trading"
] |
Scripting language for trading strategy development | 2,297,889 | <p>I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles ... | 15 | 2010-02-19T16:31:00Z | 2,298,741 | <p>Is something along the lines of <a href="http://processing.org/" rel="nofollow">Processing</a> the complexity level that you're shooting for? Processing is a good example of taking a full-blown language (Java) and reducing/simplifying the available syntax into only a subset applicable to the problem domain (problem... | 0 | 2010-02-19T18:45:26Z | [
"python",
"ruby",
"scripting",
"dsl",
"trading"
] |
Scripting language for trading strategy development | 2,297,889 | <p>I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles ... | 15 | 2010-02-19T16:31:00Z | 10,150,794 | <p>I've been working on a Python Algorithmic Trading Library (actually for backtesting, not for real trading). You may want to take a look at it: <a href="http://gbeced.github.com/pyalgotrade/" rel="nofollow">http://gbeced.github.com/pyalgotrade/</a></p>
| 1 | 2012-04-14T03:40:10Z | [
"python",
"ruby",
"scripting",
"dsl",
"trading"
] |
Scripting language for trading strategy development | 2,297,889 | <p>I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles ... | 15 | 2010-02-19T16:31:00Z | 11,813,754 | <p>I have been in the same boat building and trading with my own software. Java is not great because you want something higher level like you say. I have had a lot of success using the eclipse project xtext. <a href="http://www.eclipse.org/Xtext" rel="nofollow">http://www.eclipse.org/Xtext</a> It does all the plumbing ... | 0 | 2012-08-05T03:36:24Z | [
"python",
"ruby",
"scripting",
"dsl",
"trading"
] |
Scripting language for trading strategy development | 2,297,889 | <p>I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles ... | 15 | 2010-02-19T16:31:00Z | 14,000,559 | <p>Check out <a href="http://www.tadeveloper.com" rel="nofollow">http://www.tadeveloper.com</a> for a backtesting framework using MATLAB as a scripting language. MATLAB has the advantage that it is very powerful but you do not need to be a programmer to use it.</p>
| 1 | 2012-12-22T06:14:24Z | [
"python",
"ruby",
"scripting",
"dsl",
"trading"
] |
Creating a custom sys.stdout class? | 2,297,933 | <p>What I'm trying to do is simply have the output of some terminal commands print out to a wx.TextCtrl widget. I figured the easiest way to accomplish this is to create a custom stdout class and overload the write function to that of the widget.</p>
<p>stdout class:</p>
<pre><code>class StdOut(sys.stdout):
def ... | 5 | 2010-02-19T16:35:41Z | 2,297,993 | <p>Wouldn't <code>sys.stdout = StdOut(createdTxtCtrl)</code> create cyclical dependency? Try not reassigning <code>sys.stdout</code> to the class derived from <code>sys.stdout</code>.</p>
| -1 | 2010-02-19T16:42:58Z | [
"python",
"stdout"
] |
Creating a custom sys.stdout class? | 2,297,933 | <p>What I'm trying to do is simply have the output of some terminal commands print out to a wx.TextCtrl widget. I figured the easiest way to accomplish this is to create a custom stdout class and overload the write function to that of the widget.</p>
<p>stdout class:</p>
<pre><code>class StdOut(sys.stdout):
def ... | 5 | 2010-02-19T16:35:41Z | 2,298,003 | <p><code>sys.stdout</code> is <strong>not</strong> a <code>class</code>, it's an <strong>instance</strong> (of type <code>file</code>).</p>
<p>So, just do:</p>
<pre><code>class StdOut(object):
def __init__(self,txtctrl):
self.txtctrl = txtctrl
def write(self,string):
self.txtctrl.write(string)... | 10 | 2010-02-19T16:44:19Z | [
"python",
"stdout"
] |
Creating a custom sys.stdout class? | 2,297,933 | <p>What I'm trying to do is simply have the output of some terminal commands print out to a wx.TextCtrl widget. I figured the easiest way to accomplish this is to create a custom stdout class and overload the write function to that of the widget.</p>
<p>stdout class:</p>
<pre><code>class StdOut(sys.stdout):
def ... | 5 | 2010-02-19T16:35:41Z | 2,298,558 | <p>If all you need to implement is writing, there is no need to define a new class at all. Simply use <code>createdTxtCtrl</code> instead of <code>StdOut(createdTxtCtrl)</code>, because the former already supports the operation you need.</p>
<p>If all you need to do with stdout is direct some programs' output there, n... | 0 | 2010-02-19T18:09:52Z | [
"python",
"stdout"
] |
Python's standard library - is there a module for balanced binary tree? | 2,298,165 | <p>Is there a module for AVL or Red-Black or some other type of a balanced binary tree in the standard library of Python? I have tried to find one, but unsuccessfully (I'm relatively new to Python). </p>
| 36 | 2010-02-19T17:06:42Z | 2,298,197 | <p>there is nothing of this sort in stdlib, <a href="http://docs.python.org/library/">as far as I can see</a>, but <a href="http://pypi.python.org/pypi?%3Aaction=search&term=tree&submit=search">quick look at pypi brings up a few alternative</a>:</p>
<ul>
<li><a href="http://pypi.python.org/pypi/rbtree">rbtree<... | 12 | 2010-02-19T17:10:56Z | [
"python",
"tree",
"standard-library"
] |
Python's standard library - is there a module for balanced binary tree? | 2,298,165 | <p>Is there a module for AVL or Red-Black or some other type of a balanced binary tree in the standard library of Python? I have tried to find one, but unsuccessfully (I'm relatively new to Python). </p>
| 36 | 2010-02-19T17:06:42Z | 2,298,219 | <p>No, but there's <a href="http://www.python.org/ftp/python/contrib-09-Dec-1999/DataStructures/" rel="nofollow">AVL Tree Objects for Python</a> (very old!) and a (closed) project on SourceForge - <a href="http://sourceforge.net/projects/pyavl/" rel="nofollow">avl-trees for Python</a>.</p>
| 1 | 2010-02-19T17:13:45Z | [
"python",
"tree",
"standard-library"
] |
Python's standard library - is there a module for balanced binary tree? | 2,298,165 | <p>Is there a module for AVL or Red-Black or some other type of a balanced binary tree in the standard library of Python? I have tried to find one, but unsuccessfully (I'm relatively new to Python). </p>
| 36 | 2010-02-19T17:06:42Z | 2,298,316 | <p>No, there is not a balanced binary tree in the stdlib. However, from your comments, it sounds like you may have some other options:</p>
<ul>
<li>You say that you want a BST instead of a list for <code>O(log n)</code> searches. If searching is all you need and your data are already sorted, the <code>bisect</code> mo... | 17 | 2010-02-19T17:26:14Z | [
"python",
"tree",
"standard-library"
] |
Python's standard library - is there a module for balanced binary tree? | 2,298,165 | <p>Is there a module for AVL or Red-Black or some other type of a balanced binary tree in the standard library of Python? I have tried to find one, but unsuccessfully (I'm relatively new to Python). </p>
| 36 | 2010-02-19T17:06:42Z | 2,309,145 | <p>There have been a few instances where I have found the <a href="http://docs.python.org/library/heapq.html">heapq package</a> (in the stadndard library) to be useful, especially if at any given time you want O(1) access time to the smallest element in your collection.</p>
<p>For me, I was keeping track of a collecti... | 6 | 2010-02-22T06:13:18Z | [
"python",
"tree",
"standard-library"
] |
Python's standard library - is there a module for balanced binary tree? | 2,298,165 | <p>Is there a module for AVL or Red-Black or some other type of a balanced binary tree in the standard library of Python? I have tried to find one, but unsuccessfully (I'm relatively new to Python). </p>
| 36 | 2010-02-19T17:06:42Z | 6,081,566 | <p>There is a new package called "bintrees" which supports ubalanced, AVL and RB trees. You can find it <a href="https://pypi.python.org/pypi/bintrees/" rel="nofollow">here</a>.</p>
| 4 | 2011-05-21T11:56:56Z | [
"python",
"tree",
"standard-library"
] |
Local App Engine datastore is slow once loaded up, any suggestions? | 2,298,280 | <p>I've loaded up a local datastore with 40,000+ entries. Unfortunately,
recalling any data from it at all is very slow on my fairly new
Macbook Pro. Any suggestions on speeding things up, short of buying a
new piece of hardware? </p>
| 1 | 2010-02-19T17:21:42Z | 2,298,408 | <p><a href="http://stackoverflow.com/questions/2112950/faster-app-engine-development-datastore-alternative">This question addresses a few alternatives you could try</a>.</p>
<p>For speeding up unit testing, you can set the datastore to stay in memory only, and not flush to disk. This may not help you if you need 40,0... | 0 | 2010-02-19T17:40:29Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
Fitting a line in 3D | 2,298,390 | <p>Are there any algorithms that will return the equation of a straight line from a set of 3D data points? I can find plenty of sources which will give the equation of a line from 2D data sets, but none in 3D.</p>
<p>Thanks.</p>
| 11 | 2010-02-19T17:37:02Z | 2,304,816 | <p>If your data is fairly well behaved then it should be sufficient to find the least squares sum of the component distances. Then you can find the linear regression with z independent of x and then again independent of y.</p>
<p>Following the <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.... | 3 | 2010-02-21T04:54:58Z | [
"python",
"numpy",
"linear-algebra",
"curve-fitting"
] |
Fitting a line in 3D | 2,298,390 | <p>Are there any algorithms that will return the equation of a straight line from a set of 3D data points? I can find plenty of sources which will give the equation of a line from 2D data sets, but none in 3D.</p>
<p>Thanks.</p>
| 11 | 2010-02-19T17:37:02Z | 2,333,251 | <p>If you are trying to predict one value from the other two, then you should use <code>lstsq</code> with the <code>a</code> argument as your independent variables (plus a column of 1's to estimate an intercept) and <code>b</code> as your dependent variable. </p>
<p>If, on the other hand, you just want to get the best... | 31 | 2010-02-25T10:28:15Z | [
"python",
"numpy",
"linear-algebra",
"curve-fitting"
] |
warnings emitted during 'easy_install' | 2,298,403 | <p>When I <code>easy_install</code> some python modules, warnings such as:</p>
<pre><code><some module>: module references __file__
<some module>: module references __path__
<some module>: module MAY be using inspect.trace
<some module>: module MAY be using inspect.getsourcefile
</code></pre>
... | 3 | 2010-02-19T17:39:29Z | 2,438,910 | <p><code>easy_install</code> doesn't like use of <code>__file__</code> and <code>__path__</code> not so much because they're dangerous, but because packages that use them almost always fail to run out of zipped eggs. </p>
<p><code>easy_install</code> is warning because it'll install "less efficiently" into an unzipped... | 5 | 2010-03-13T15:41:08Z | [
"python",
"warnings",
"easy-install"
] |
warnings emitted during 'easy_install' | 2,298,403 | <p>When I <code>easy_install</code> some python modules, warnings such as:</p>
<pre><code><some module>: module references __file__
<some module>: module references __path__
<some module>: module MAY be using inspect.trace
<some module>: module MAY be using inspect.getsourcefile
</code></pre>
... | 3 | 2010-02-19T17:39:29Z | 2,438,932 | <p>I wouldn't worry about it. As durin42 notes, this just means that setuptools won't zip the egg when it puts it into site packages. If you don't want to see these messages, I believe you can just use the <code>-Z</code> flag to <code>easy_install</code>. That will make it always unzip the egg.</p>
<p>I recommend ... | 0 | 2010-03-13T15:46:29Z | [
"python",
"warnings",
"easy-install"
] |
Are any of these quad-tree libraries any good? | 2,298,517 | <p>It appears that a certain project of mine will require the use of quad-trees, something that I have never worked with before. From what I have read they should allow substantial performance enhancements than a brute-force attempt at the problem would yield. Are any of these python modules any good?</p>
<ul>
<li><a ... | 10 | 2010-02-19T17:59:45Z | 2,299,486 | <p>Sometimes, it is not obvious how to implement data structures like trees in Python.</p>
<p>For instance,</p>
<pre><code> D
/ \
B F
/ \ / \
A C E G
</code></pre>
<p>is a simple binary tree structure. In Python, you would represent it like so:</p>
<p><code>[D,B,F]</code> is a node with ... | 1 | 2010-02-19T20:54:44Z | [
"python",
"performance",
"quadtree"
] |
Are any of these quad-tree libraries any good? | 2,298,517 | <p>It appears that a certain project of mine will require the use of quad-trees, something that I have never worked with before. From what I have read they should allow substantial performance enhancements than a brute-force attempt at the problem would yield. Are any of these python modules any good?</p>
<ul>
<li><a ... | 10 | 2010-02-19T17:59:45Z | 2,476,103 | <p>The python package index produces 2 other libraries when searching for quadtree : <a href="http://pypi.python.org/pypi?%3Aaction=search&term=quadtree&submit=search" rel="nofollow">http://pypi.python.org/pypi?%3Aaction=search&term=quadtree&submit=search</a></p>
<p>disclaimer : never used quadtrees or... | 1 | 2010-03-19T09:18:53Z | [
"python",
"performance",
"quadtree"
] |
Are any of these quad-tree libraries any good? | 2,298,517 | <p>It appears that a certain project of mine will require the use of quad-trees, something that I have never worked with before. From what I have read they should allow substantial performance enhancements than a brute-force attempt at the problem would yield. Are any of these python modules any good?</p>
<ul>
<li><a ... | 10 | 2010-02-19T17:59:45Z | 13,362,187 | <p>In <a href="http://stackoverflow.com/questions/9810775/name-of-this-algorithm-and-is-there-a-numpy-scipy-implementation-of-it#comment12497888_9810817">this comment</a>, <a href="http://stackoverflow.com/users/325565/joferkington">joferkington</a> refers to the current question and says:</p>
<blockquote>
<p>Just f... | 7 | 2012-11-13T14:08:25Z | [
"python",
"performance",
"quadtree"
] |
Are any of these quad-tree libraries any good? | 2,298,517 | <p>It appears that a certain project of mine will require the use of quad-trees, something that I have never worked with before. From what I have read they should allow substantial performance enhancements than a brute-force attempt at the problem would yield. Are any of these python modules any good?</p>
<ul>
<li><a ... | 10 | 2010-02-19T17:59:45Z | 23,859,736 | <p>Another library to check out is <a href="http://thepythongischallenge.wordpress.com/2014/05/23/introducing-a-pure-python-quadtree-spatial-index-for-gis-use/" rel="nofollow">PyQuadTree</a>, a pure python quadtree index that also works on Python 3x. All you need to add an item is its bounding box as a 4-length sequenc... | 2 | 2014-05-25T20:37:55Z | [
"python",
"performance",
"quadtree"
] |
Most optimal way to programmatically check if site is running locally or on a server with Django? | 2,298,657 | <p>Currently I have this in my <code>settings.py</code> file: </p>
<pre><code>DEBUG = True
LOCAL = True
TEMPLATE_DEBUG = DEBUG
SITE_TITLE = 'Stack Overflow Question'
REMOTE_SITE_URL = "http://************:8080"
LOCAL_SITE_URL = "http://************:8000"
ADMINS = (
# ('Your Name', 'your_email@domain.com'),
)
... | 1 | 2010-02-19T18:28:53Z | 2,298,734 | <p>Checking if a file exists will not occur every time a render occurs. It will actually only occur whenever you interpreter process is started, which all depends on your deployment configuration. This will depend on a variety on your webserver setup, but if you are using apache, chiefly MaxRequestPerChild and StartS... | 4 | 2010-02-19T18:43:58Z | [
"python",
"database",
"django"
] |
Is nested dictionary in design ok? | 2,298,723 | <p>My data is structured in a way that I ended up creating a nested dictionary in my design like:</p>
<pre><code>my_dict = {"a": {"b": {"c":"I am c"}}}
my_dict["a"]["b"]["c"]
</code></pre>
<p>Is it usual! or we have some other better alternatives (using objects!)?</p>
| 3 | 2010-02-19T18:41:48Z | 2,298,746 | <p>You could use a tuple to store your values in a flat dictionary:</p>
<pre><code>d = {}
d[a, b, c] = e
</code></pre>
<p>It all depends on what you are doing, but remember that <a href="http://www.python.org/dev/peps/pep-0020/" rel="nofollow">The Zen of Python</a> says that flat is better than nested :)</p>
| 6 | 2010-02-19T18:46:15Z | [
"python",
"data-structures",
"dictionary"
] |
Is nested dictionary in design ok? | 2,298,723 | <p>My data is structured in a way that I ended up creating a nested dictionary in my design like:</p>
<pre><code>my_dict = {"a": {"b": {"c":"I am c"}}}
my_dict["a"]["b"]["c"]
</code></pre>
<p>Is it usual! or we have some other better alternatives (using objects!)?</p>
| 3 | 2010-02-19T18:41:48Z | 2,298,747 | <p>There is nothing inherently wrong with nested dicts. Anything can be a dict value, and it can make sense for a dict to be one.</p>
<p>A lot of the time when people make nested dicts, their problems could be solved slightly more easily by using a dict with tuples for keys. Instead of accessing a value as <code>d[a][... | 6 | 2010-02-19T18:46:31Z | [
"python",
"data-structures",
"dictionary"
] |
Is nested dictionary in design ok? | 2,298,723 | <p>My data is structured in a way that I ended up creating a nested dictionary in my design like:</p>
<pre><code>my_dict = {"a": {"b": {"c":"I am c"}}}
my_dict["a"]["b"]["c"]
</code></pre>
<p>Is it usual! or we have some other better alternatives (using objects!)?</p>
| 3 | 2010-02-19T18:41:48Z | 2,298,903 | <p>At first they may seem like a good idea, but usually you'll find yourself needing more information/functionality from them. If that happens, your first reaction may be "I need more hashes", but all this can be avoided by using a simpler hierarchy ... it would be easier too.</p>
| 1 | 2010-02-19T19:13:12Z | [
"python",
"data-structures",
"dictionary"
] |
Is nested dictionary in design ok? | 2,298,723 | <p>My data is structured in a way that I ended up creating a nested dictionary in my design like:</p>
<pre><code>my_dict = {"a": {"b": {"c":"I am c"}}}
my_dict["a"]["b"]["c"]
</code></pre>
<p>Is it usual! or we have some other better alternatives (using objects!)?</p>
| 3 | 2010-02-19T18:41:48Z | 2,299,418 | <p>I would not build complex data structures like that in the code itself. There is too great a risk of making a mistake with punctuation, and anyone reading the code will tend to get confused by this. Far better to put your constant data in some simple form, with no nesting of data structures. Then if you need to have... | 0 | 2010-02-19T20:46:00Z | [
"python",
"data-structures",
"dictionary"
] |
Is nested dictionary in design ok? | 2,298,723 | <p>My data is structured in a way that I ended up creating a nested dictionary in my design like:</p>
<pre><code>my_dict = {"a": {"b": {"c":"I am c"}}}
my_dict["a"]["b"]["c"]
</code></pre>
<p>Is it usual! or we have some other better alternatives (using objects!)?</p>
| 3 | 2010-02-19T18:41:48Z | 2,299,502 | <p>Maybe one nested dictionary is okay... but even then you're asking to get confused later and there's a pretty good chance that if you're already doing nested stuff you're gonna want more information in it later.</p>
<p>In general I'd say take a step back and see if all that information in the dictionaries is needed... | 0 | 2010-02-19T20:57:02Z | [
"python",
"data-structures",
"dictionary"
] |
How do I use Flickzeug to get interactive tracebacks from a paste deploy WSGI pipeline? | 2,299,173 | <p>I'd like to use Flickzeug to see interactive tracebacks by adding it to my paste deploy file's <code>pipeline</code>. The following doesn't work. What will?</p>
<pre><code>[pipeline]
pipeline =
flickzeug
myapp
</code></pre>
| 0 | 2010-02-19T19:57:58Z | 2,368,468 | <p>Use the <code>filter-with</code> directive in your application declaration.</p>
<pre><code>[app:main]
use = ...
...
filter-with = flickzeug
[filter:flickzeug]
use = egg:...#...
...</code></pre>
<p>For more information, see the first example in the Filter Composition section of the <a href="http://pythonpaste.or... | 0 | 2010-03-03T03:01:54Z | [
"python",
"wsgi",
"paster"
] |
IRC bot can't join channel | 2,299,210 | <pre><code>import socket
irc = 'irc.hack3r.com'
port = 6667
channel = '#chat'
sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sck.connect((irc, port))
sck.send('NICK supaBOT\r\n')
sck.send('USER supaBOT supaBOT supaBOT :supaBOT Script\r\n')
sck.send('JOIN #chat' + '\r\n')
data = ''
while True:
data = sck.... | 3 | 2010-02-19T20:06:24Z | 2,299,223 | <p>It sounds like You are not registered and that is a requirement for joining that channel. You will have to register your nick and then identify before joining. </p>
<p>Also, trying to make an irc bot with bare sockets is not a good idea. This code does not implement RFC 1459 to a useful level and it conflates the l... | 2 | 2010-02-19T20:08:07Z | [
"python",
"irc"
] |
IRC bot can't join channel | 2,299,210 | <pre><code>import socket
irc = 'irc.hack3r.com'
port = 6667
channel = '#chat'
sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sck.connect((irc, port))
sck.send('NICK supaBOT\r\n')
sck.send('USER supaBOT supaBOT supaBOT :supaBOT Script\r\n')
sck.send('JOIN #chat' + '\r\n')
data = ''
while True:
data = sck.... | 3 | 2010-02-19T20:06:24Z | 2,299,446 | <p>The particular channel you're trying to join requires you to be registered with the nickserv for that server. Try going on the server with a regular IRC client and creating a channel yourself, and tell the bot to join that.</p>
| 0 | 2010-02-19T20:49:43Z | [
"python",
"irc"
] |
IRC bot can't join channel | 2,299,210 | <pre><code>import socket
irc = 'irc.hack3r.com'
port = 6667
channel = '#chat'
sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sck.connect((irc, port))
sck.send('NICK supaBOT\r\n')
sck.send('USER supaBOT supaBOT supaBOT :supaBOT Script\r\n')
sck.send('JOIN #chat' + '\r\n')
data = ''
while True:
data = sck.... | 3 | 2010-02-19T20:06:24Z | 9,966,039 | <p>Mike Graham is wrong. What's wrong is you send the JOIN command too early. It takes a while for the server to register your NICK and USER commands, hence the error "Nick not registered".
See this reply: <a href="http://stackoverflow.com/questions/4770598/python-irc-bot-wont-join">Python IRC bot won't join</a>. <... | 11 | 2012-04-01T16:23:32Z | [
"python",
"irc"
] |
IRC bot can't join channel | 2,299,210 | <pre><code>import socket
irc = 'irc.hack3r.com'
port = 6667
channel = '#chat'
sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sck.connect((irc, port))
sck.send('NICK supaBOT\r\n')
sck.send('USER supaBOT supaBOT supaBOT :supaBOT Script\r\n')
sck.send('JOIN #chat' + '\r\n')
data = ''
while True:
data = sck.... | 3 | 2010-02-19T20:06:24Z | 14,185,257 | <h2>Python twisted irc client</h2>
<h2>Installation</h2>
<p>sudo yum install python-twisted-words</p>
<p>or</p>
<p>sudo apt-get install python-twisted-words</p>
<h2>API Documentation</h2>
<p><a href="http://twistedmatrix.com/documents/8.2.0/api/twisted.words.protocols.irc.IRCClient.html" rel="nofollow">http://twi... | 0 | 2013-01-06T18:21:55Z | [
"python",
"irc"
] |
How do quickly search through a .csv file in Python | 2,299,454 | <p>I'm reading a 6 million entry .csv file with Python, and I want to be able to search through this file for a particular entry.</p>
<p>Are there any tricks to search the entire file? Should you read the whole thing into a dictionary or should you perform a search every time? I tried loading it into a dictionary but ... | 3 | 2010-02-19T20:51:01Z | 2,299,771 | <p>If the csv file isn't changing, load in it into a database, where searching is fast and easy. If you're not familiar with SQL, you'll need to brush up on that though.</p>
<p>Here is a rough example of inserting from a csv into a sqlite table. Example csv is ';' delimited, and has 2 columns. </p>
<pre><code>import... | 6 | 2010-02-19T21:34:35Z | [
"python",
"dictionary",
"csv",
"large-files"
] |
How do quickly search through a .csv file in Python | 2,299,454 | <p>I'm reading a 6 million entry .csv file with Python, and I want to be able to search through this file for a particular entry.</p>
<p>Are there any tricks to search the entire file? Should you read the whole thing into a dictionary or should you perform a search every time? I tried loading it into a dictionary but ... | 3 | 2010-02-19T20:51:01Z | 2,300,407 | <p>Well, if your words aren't too big (meaning they'll fit in memory), then here is a simple way to do this (I'm assuming that they are all words). </p>
<pre><code>from bisect import bisect_left
f = open('myfile.csv')
words = []
for line in f:
words.extend(line.strip().split(','))
wordtofind = 'bacon'
ind = bis... | 1 | 2010-02-19T23:52:20Z | [
"python",
"dictionary",
"csv",
"large-files"
] |
How do quickly search through a .csv file in Python | 2,299,454 | <p>I'm reading a 6 million entry .csv file with Python, and I want to be able to search through this file for a particular entry.</p>
<p>Are there any tricks to search the entire file? Should you read the whole thing into a dictionary or should you perform a search every time? I tried loading it into a dictionary but ... | 3 | 2010-02-19T20:51:01Z | 2,300,537 | <p>you can use memory mapping for really big files</p>
<pre><code>import mmap,os,re
reportFile = open( "big_file" )
length = os.fstat( reportFile.fileno() ).st_size
try:
mapping = mmap.mmap( reportFile.fileno(), length, mmap.MAP_PRIVATE, mmap.PROT_READ )
except AttributeError:
mapping = mmap.mmap( reportFile.f... | 4 | 2010-02-20T00:29:01Z | [
"python",
"dictionary",
"csv",
"large-files"
] |
How do quickly search through a .csv file in Python | 2,299,454 | <p>I'm reading a 6 million entry .csv file with Python, and I want to be able to search through this file for a particular entry.</p>
<p>Are there any tricks to search the entire file? Should you read the whole thing into a dictionary or should you perform a search every time? I tried loading it into a dictionary but ... | 3 | 2010-02-19T20:51:01Z | 2,443,606 | <p>You can't go directly to a specific line in the file because lines are variable-length, so the only way to know when line #n starts is to search for the first n newlines. And it's not enough to just look for '\n' characters because CSV allows newlines in table cells, so you really do have to parse the file anyway.<... | 1 | 2010-03-14T20:19:51Z | [
"python",
"dictionary",
"csv",
"large-files"
] |
How do quickly search through a .csv file in Python | 2,299,454 | <p>I'm reading a 6 million entry .csv file with Python, and I want to be able to search through this file for a particular entry.</p>
<p>Are there any tricks to search the entire file? Should you read the whole thing into a dictionary or should you perform a search every time? I tried loading it into a dictionary but ... | 3 | 2010-02-19T20:51:01Z | 3,279,041 | <p>my idea is to use python zodb module to store dictionaty type data and then create new csv file using that data structure. do all your operation at that time.</p>
| 0 | 2010-07-19T07:07:57Z | [
"python",
"dictionary",
"csv",
"large-files"
] |
Python Thread/Queue issue | 2,299,478 | <p>I'm creating a threaded python script that has a collection of files that is put into a queue and then an unknown amount of threads (default is 3) to start downloading. When each of the threads complete it updates the stdout with the queue status and a percentage. All the files are being downloaded but the status ... | 2 | 2010-02-19T20:53:28Z | 2,299,582 | <p>You can't check the queue size in one statement, and then <code>.get()</code> from the queue in the next. In the meantime the whole world may have changed. The <code>.get()</code> method call is the single atomic operation you need to call. If it raises <code>Empty</code> or blocks, the queue is empty.</p>
<p>You... | 4 | 2010-02-19T21:10:15Z | [
"python",
"multithreading",
"queue"
] |
Python Thread/Queue issue | 2,299,478 | <p>I'm creating a threaded python script that has a collection of files that is put into a queue and then an unknown amount of threads (default is 3) to start downloading. When each of the threads complete it updates the stdout with the queue status and a percentage. All the files are being downloaded but the status ... | 2 | 2010-02-19T20:53:28Z | 2,300,072 | <p>If you'd like to use the <code>multiprocessing</code> module, it includes a very nice parallel <code>imap_unordered</code>, which would reduce your problem to the very elegant:</p>
<pre><code>import multiprocessing, sys
class ParallelDownload:
def __init__(self, urls, processcount=3):
self.total_items ... | 2 | 2010-02-19T22:28:05Z | [
"python",
"multithreading",
"queue"
] |
Google Books API - How do I separate Book from Book Edition? | 2,299,589 | <p>I'm using <strong>Google Book Search API</strong> to add missings bits and pieces to my database.</p>
<p>Problem is that The API gives me back a list of book editions, and not <strong>reference to the original book</strong> itself.</p>
<p>The data I'm trying to get is this:</p>
<blockquote>
<p>Original title: <... | 1 | 2010-02-19T21:11:46Z | 2,561,157 | <p>Try with this snippet:</p>
<pre><code>entry = self.service.get_by_google_id("XV0NAQAAIAAJ")
print entry.dc_title[0].text
print entry.date.text
</code></pre>
<p>Result is:<br>
<strong>The hobbit<br>
1937</strong></p>
| 1 | 2010-04-01T14:38:37Z | [
"python",
"google-api"
] |
How to I extract floats from a file in Python? | 2,299,609 | <p>So, I have a file that looks like this:</p>
<pre><code># 3e98.mtz MR_AUTO with model 200la_.pdb
SPACegroup HALL P 2yb #P 1 21 1
SOLU SET RFZ=3.0 TFZ=4.7 PAK=0 LLG=30
SOLU 6DIM ENSE 200la_ EULER 321.997 124.066 234.744 FRAC -0.14681 0.50245 -0.05722
SOLU SET RFZ=3.3 TFZ=4.2 PAK=0 LLG=30
SOLU 6DIM ENSE 200la_ EULER 3... | 2 | 2010-02-19T21:14:21Z | 2,299,631 | <p>Here's one way.</p>
<pre><code>def floats( aList ):
for v in aList:
try:
yield float(v)
except ValueError:
pass
a = list( floats( [....] ) )
</code></pre>
| 11 | 2010-02-19T21:16:16Z | [
"python",
"list",
"floating-point",
"loops"
] |
How to I extract floats from a file in Python? | 2,299,609 | <p>So, I have a file that looks like this:</p>
<pre><code># 3e98.mtz MR_AUTO with model 200la_.pdb
SPACegroup HALL P 2yb #P 1 21 1
SOLU SET RFZ=3.0 TFZ=4.7 PAK=0 LLG=30
SOLU 6DIM ENSE 200la_ EULER 321.997 124.066 234.744 FRAC -0.14681 0.50245 -0.05722
SOLU SET RFZ=3.3 TFZ=4.2 PAK=0 LLG=30
SOLU 6DIM ENSE 200la_ EULER 3... | 2 | 2010-02-19T21:14:21Z | 2,299,644 | <pre><code>floats = []
all = ['#', '3e98.mtz', 'MR_AUTO', 'with', 'model', '200la_.pdb', 'SPACegroup', 'HALL', 'P', '2yb', '#P', '1', '21', '1', 'SOLU', 'SET', 'RFZ=3.0', 'TFZ=4.7', 'PAK=0', 'LLG=30', 'SOLU', '6DIM', 'ENSE', '200la_', 'EULER', '321.997', '124.066', '234.744', 'FRAC', '-0.14681', '0.50245', '-0.05722', ... | 7 | 2010-02-19T21:17:16Z | [
"python",
"list",
"floating-point",
"loops"
] |
How to I extract floats from a file in Python? | 2,299,609 | <p>So, I have a file that looks like this:</p>
<pre><code># 3e98.mtz MR_AUTO with model 200la_.pdb
SPACegroup HALL P 2yb #P 1 21 1
SOLU SET RFZ=3.0 TFZ=4.7 PAK=0 LLG=30
SOLU 6DIM ENSE 200la_ EULER 321.997 124.066 234.744 FRAC -0.14681 0.50245 -0.05722
SOLU SET RFZ=3.3 TFZ=4.2 PAK=0 LLG=30
SOLU 6DIM ENSE 200la_ EULER 3... | 2 | 2010-02-19T21:14:21Z | 2,299,708 | <pre><code>def is_float(i):
try:
float(i)
return True
except ValueError:
return False
L=['#', '3e98.mtz', 'MR_AUTO', 'with', 'model', '200la_.pdb', 'SPACegroup', 'HALL', 'P', '2yb', '#P', '1', '21', '1', 'SOLU', 'SET', 'RFZ=3.0', 'TFZ=4.7', 'PAK=0', 'LLG=30', 'SOLU'... | 3 | 2010-02-19T21:25:50Z | [
"python",
"list",
"floating-point",
"loops"
] |
How to I extract floats from a file in Python? | 2,299,609 | <p>So, I have a file that looks like this:</p>
<pre><code># 3e98.mtz MR_AUTO with model 200la_.pdb
SPACegroup HALL P 2yb #P 1 21 1
SOLU SET RFZ=3.0 TFZ=4.7 PAK=0 LLG=30
SOLU 6DIM ENSE 200la_ EULER 321.997 124.066 234.744 FRAC -0.14681 0.50245 -0.05722
SOLU SET RFZ=3.3 TFZ=4.2 PAK=0 LLG=30
SOLU 6DIM ENSE 200la_ EULER 3... | 2 | 2010-02-19T21:14:21Z | 2,300,304 | <p>If you display your input in a manner that discourages answerers from examining its structure, and you ask questions like "how do I extract only the floating point numbers", and bury useful information like "In each file that I am looking at, there is 6 numbers like that in each line" in comments, you will get knee-... | 0 | 2010-02-19T23:27:15Z | [
"python",
"list",
"floating-point",
"loops"
] |
python and process | 2,299,627 | <p>What is the best way in python find the process name and owner?</p>
<p>Now i use WMI, but this version is too slow.</p>
| 0 | 2010-02-19T21:15:53Z | 2,505,040 | <p>Process name: is sys.argv[0] not sufficient for your purposes?</p>
| 0 | 2010-03-24T02:54:09Z | [
"python",
"windows",
"wmi"
] |
python and process | 2,299,627 | <p>What is the best way in python find the process name and owner?</p>
<p>Now i use WMI, but this version is too slow.</p>
| 0 | 2010-02-19T21:15:53Z | 4,229,492 | <p>By using <a href="https://github.com/giampaolo/psutil" rel="nofollow">https://github.com/giampaolo/psutil</a>:</p>
<pre><code>>>> import psutil, os
>>> p = psutil.Process(os.getpid())
>>> p.name()
'python.exe'
>>> p.username()
'giampaolo'
>>>
</code></pre>
| 1 | 2010-11-19T21:23:00Z | [
"python",
"windows",
"wmi"
] |
Combining words in Python (permutations?) | 2,299,671 | <p>Suppose I have 4 words, as a string.
How do I join them all like this?</p>
<pre><code>s = orange apple grapes pear
</code></pre>
<p>The result would be a String:</p>
<pre><code>"orangeapple/orangegrapes/orangepear/applegrapes/applepear/grapespear/orangeapplegrapes/orangeapplepear/applegrapespear"
</code></pre>
<... | 4 | 2010-02-19T21:20:32Z | 2,299,728 | <p>Maybe this is what you want?</p>
<pre><code>s = "orange apple grapes pear"
from itertools import product
l = s.split()
r='/'.join(''.join(k*v for k,v in zip(l, x))
for x in product(range(2), repeat=len(l))
if sum(x) > 1)
print r
</code></pre>
<p>If run on 'a b c' (for clarity) the result ... | 4 | 2010-02-19T21:28:50Z | [
"python",
"string",
"permutation"
] |
Combining words in Python (permutations?) | 2,299,671 | <p>Suppose I have 4 words, as a string.
How do I join them all like this?</p>
<pre><code>s = orange apple grapes pear
</code></pre>
<p>The result would be a String:</p>
<pre><code>"orangeapple/orangegrapes/orangepear/applegrapes/applepear/grapespear/orangeapplegrapes/orangeapplepear/applegrapespear"
</code></pre>
<... | 4 | 2010-02-19T21:20:32Z | 2,299,743 | <pre><code>s = 'orange apple grapes pear'
list_words = s.split()
num = len(list_words)
ans = []
for i in xrange(1,2**num-1):
cur = []
for j,word in enumerate(list_words):
if i & (1 << j):
cur.append(word)
if len(cur) > 1:
ans.append(''.join(cur))
print '/'.join(ans)
</code></pre>
<p... | 1 | 2010-02-19T21:30:37Z | [
"python",
"string",
"permutation"
] |
Combining words in Python (permutations?) | 2,299,671 | <p>Suppose I have 4 words, as a string.
How do I join them all like this?</p>
<pre><code>s = orange apple grapes pear
</code></pre>
<p>The result would be a String:</p>
<pre><code>"orangeapple/orangegrapes/orangepear/applegrapes/applepear/grapespear/orangeapplegrapes/orangeapplepear/applegrapespear"
</code></pre>
<... | 4 | 2010-02-19T21:20:32Z | 2,299,893 | <pre><code>>>> import itertools
>>> from itertools import combinations
>>> s = "orange apple grapes pear".split()
>>> res=[]
>>> for i in range(2,len(s)+1):
... res += [''.join(x) for x in combinations(s,i)]
...
>>> '/'.join(res)
'orangeapple/orangegrapes/orang... | 1 | 2010-02-19T21:56:46Z | [
"python",
"string",
"permutation"
] |
Combining words in Python (permutations?) | 2,299,671 | <p>Suppose I have 4 words, as a string.
How do I join them all like this?</p>
<pre><code>s = orange apple grapes pear
</code></pre>
<p>The result would be a String:</p>
<pre><code>"orangeapple/orangegrapes/orangepear/applegrapes/applepear/grapespear/orangeapplegrapes/orangeapplepear/applegrapespear"
</code></pre>
<... | 4 | 2010-02-19T21:20:32Z | 2,299,993 | <pre><code>>>> s = "orange apple grapes pear".split()
>>> '/'.join(''.join(k) for k in [[s[j] for j in range(len(s)) if 1<<j&i] for i in range(1<<len(s))] if len(k)>1)
'orangeapple/orangegrapes/applegrapes/orangeapplegrapes/orangepear/applepear/orangeapplepear/grapespear/orangegrape... | 1 | 2010-02-19T22:13:21Z | [
"python",
"string",
"permutation"
] |
Combining words in Python (permutations?) | 2,299,671 | <p>Suppose I have 4 words, as a string.
How do I join them all like this?</p>
<pre><code>s = orange apple grapes pear
</code></pre>
<p>The result would be a String:</p>
<pre><code>"orangeapple/orangegrapes/orangepear/applegrapes/applepear/grapespear/orangeapplegrapes/orangeapplepear/applegrapespear"
</code></pre>
<... | 4 | 2010-02-19T21:20:32Z | 2,300,024 | <pre><code>>>> from itertools import combinations
>>> s = "orange apple grapes pear".split()
>>> '/'.join([''.join(y) for y in [ x for z in range(len(s)) for x in combinations(s,z)] if len(y)>1])
'orangeapple/orangegrapes/orangepear/applegrapes/applepear/grapespear/orangeapplegrapes/orange... | 4 | 2010-02-19T22:19:45Z | [
"python",
"string",
"permutation"
] |
Positional Rankings and Dealing with Ties in Python | 2,299,696 | <p><em>(I apologize that previous versions of this question displayed the wrong function that I need to fix, this has been remedied and I hope the question makes a little more sense now.)</em></p>
<p>I have a list of objects with scores, and I'm attempting to assign rank to them based on those scores. Below is basical... | 2 | 2010-02-19T21:23:43Z | 2,300,270 | <p>The way to do this is not to calculate the element's position is some arbitrary sequence, but rather to calculate how many other elements have a better score.</p>
<p><strong>EDIT:</strong></p>
<p>By popular demand, O(n)'ed and everything:</p>
<pre><code>positions = {}
cur_score = None # Score we're examining
cur_... | 2 | 2010-02-19T23:16:33Z | [
"python",
"django",
"math"
] |
Positional Rankings and Dealing with Ties in Python | 2,299,696 | <p><em>(I apologize that previous versions of this question displayed the wrong function that I need to fix, this has been remedied and I hope the question makes a little more sense now.)</em></p>
<p>I have a list of objects with scores, and I'm attempting to assign rank to them based on those scores. Below is basical... | 2 | 2010-02-19T21:23:43Z | 2,308,223 | <p>I'm having to make a bunch of assumptions about what it is you want to do, but here's an attempt:</p>
<pre><code>scores = {
'lorem': 100,
'ipsum': 200,
'dolor': 300,
'sit': 300,
'amet': 300,
'quia': 400,
'consectetur': 500,
'adipiscing': 500,
'elit': 600,
}
groups = {}
for (... | 0 | 2010-02-22T01:03:09Z | [
"python",
"django",
"math"
] |
Positional Rankings and Dealing with Ties in Python | 2,299,696 | <p><em>(I apologize that previous versions of this question displayed the wrong function that I need to fix, this has been remedied and I hope the question makes a little more sense now.)</em></p>
<p>I have a list of objects with scores, and I'm attempting to assign rank to them based on those scores. Below is basical... | 2 | 2010-02-19T21:23:43Z | 2,308,641 | <p><strong>=== Update after change/clarification of specs ===</strong></p>
<pre><code># coding: ascii
def ranks_from_scores(sorted_scores):
"""sorted_scores: a list of tuples (object_id, score), sorted by score DESCENDING
return a mapping of object IDs to ranks
"""
ranks = {}
previous_score = o... | 2 | 2010-02-22T03:35:52Z | [
"python",
"django",
"math"
] |
Positional Rankings and Dealing with Ties in Python | 2,299,696 | <p><em>(I apologize that previous versions of this question displayed the wrong function that I need to fix, this has been remedied and I hope the question makes a little more sense now.)</em></p>
<p>I have a list of objects with scores, and I'm attempting to assign rank to them based on those scores. Below is basical... | 2 | 2010-02-19T21:23:43Z | 2,308,642 | <p>Looks like you can use the <code>sorted</code> and <code>enumerate</code> builtins, the <code>groupby</code> method from <code>itertools</code> and the <code>itemgetter</code> method from <code>operator</code>. Assumes higher scores are better... (if lower scores are better, change <code>reverse=True</code> to <code... | 1 | 2010-02-22T03:36:51Z | [
"python",
"django",
"math"
] |
Positional Rankings and Dealing with Ties in Python | 2,299,696 | <p><em>(I apologize that previous versions of this question displayed the wrong function that I need to fix, this has been remedied and I hope the question makes a little more sense now.)</em></p>
<p>I have a list of objects with scores, and I'm attempting to assign rank to them based on those scores. Below is basical... | 2 | 2010-02-19T21:23:43Z | 2,308,975 | <p>Here is a simple way to do it</p>
<pre><code>last = None
position = 0
delta = 1
for key, value in sorted_list:
if value is not None:
if value != last:
position += delta
delta = 1
else:
delta += 1
# i believe this is supposed to be [key] not [value] in ... | 0 | 2010-02-22T05:20:34Z | [
"python",
"django",
"math"
] |
Positional Rankings and Dealing with Ties in Python | 2,299,696 | <p><em>(I apologize that previous versions of this question displayed the wrong function that I need to fix, this has been remedied and I hope the question makes a little more sense now.)</em></p>
<p>I have a list of objects with scores, and I'm attempting to assign rank to them based on those scores. Below is basical... | 2 | 2010-02-19T21:23:43Z | 2,309,099 | <pre><code>>>> sorted_scores = [
... ('Apolo Ohno', 0),
... ('Shanie Davis', -1),
... ('Bodie Miller', -2),
... ('Lindsay Vohn', -3),
... ('Shawn White', -3),
... ('Bryan Veloso',-4)
... ]
>>>
>>> from itertools import groupby
>>> from operator import itemg... | 0 | 2010-02-22T05:59:57Z | [
"python",
"django",
"math"
] |
Positional Rankings and Dealing with Ties in Python | 2,299,696 | <p><em>(I apologize that previous versions of this question displayed the wrong function that I need to fix, this has been remedied and I hope the question makes a little more sense now.)</em></p>
<p>I have a list of objects with scores, and I'm attempting to assign rank to them based on those scores. Below is basical... | 2 | 2010-02-19T21:23:43Z | 2,309,105 | <p><strong>Solution</strong></p>
<p>Here's one simple way to do it by modifying your code a little rather than importing modules:</p>
<pre><code>prev = None
rank = 0
incr = 1
positions = {}
for key, value in sorted_list:
if value is not None:
if value != prev:
rank += incr
incr = 1... | 1 | 2010-02-22T06:01:23Z | [
"python",
"django",
"math"
] |
Positional Rankings and Dealing with Ties in Python | 2,299,696 | <p><em>(I apologize that previous versions of this question displayed the wrong function that I need to fix, this has been remedied and I hope the question makes a little more sense now.)</em></p>
<p>I have a list of objects with scores, and I'm attempting to assign rank to them based on those scores. Below is basical... | 2 | 2010-02-19T21:23:43Z | 2,309,122 | <pre><code>>>> sorted_scores = [
... ('Apolo Ohno', 0),
... ('Shanie Davis', -1),
... ('Bodie Miller', -2),
... ('Lindsay Vohn', -3),
... ('Shawn White', -3),
... ('Bryan Veloso',-4)
... ]
>>>
>>> res = {}
>>> prev = None
>>> for i,(k,v) in enumera... | 5 | 2010-02-22T06:06:54Z | [
"python",
"django",
"math"
] |
Building a wiki application? | 2,299,697 | <p>I'm building this app in Python with Django.</p>
<p>I would like to give parts of the site <strong>wiki like functionality</strong>,
but I don't know how to go on about <strong>reliability and security</strong>.</p>
<ul>
<li>Make sure that good content is not ruined</li>
<li>Check for quality</li>
<li>Prevent spam... | 0 | 2010-02-19T21:23:47Z | 2,299,726 | <p>You could try using <a href="https://launchpad.net/django-wikiapp" rel="nofollow">Django Wikiapp</a>, which gives you most of the features you want in a wiki, including history and the ability to revert to older versions of an article. I have personally used this app and it's pretty self-explanatory; they also have ... | 2 | 2010-02-19T21:28:34Z | [
"python",
"django",
"django-models",
"wiki"
] |
Building a wiki application? | 2,299,697 | <p>I'm building this app in Python with Django.</p>
<p>I would like to give parts of the site <strong>wiki like functionality</strong>,
but I don't know how to go on about <strong>reliability and security</strong>.</p>
<ul>
<li>Make sure that good content is not ruined</li>
<li>Check for quality</li>
<li>Prevent spam... | 0 | 2010-02-19T21:23:47Z | 2,299,776 | <p>Assuming that there will be a community of users you can provide good tools for them to spot problems and easily undo damage. The most important of these is to provide a Recent Changes page that summarizes recent edits. Then each page that can be edited should retain prior versions of the page that can be used to re... | 1 | 2010-02-19T21:36:40Z | [
"python",
"django",
"django-models",
"wiki"
] |
Building a wiki application? | 2,299,697 | <p>I'm building this app in Python with Django.</p>
<p>I would like to give parts of the site <strong>wiki like functionality</strong>,
but I don't know how to go on about <strong>reliability and security</strong>.</p>
<ul>
<li>Make sure that good content is not ruined</li>
<li>Check for quality</li>
<li>Prevent spam... | 0 | 2010-02-19T21:23:47Z | 2,299,849 | <ul>
<li>Make sure that good content is not ruined = version each edit and allow roll-backs. </li>
<li>Check for quality = get people to help with that</li>
<li>Prevent spam from invading the site = get people to help with that, require login, add a captcha if need be, use nofollow for all links</li>
</ul>
| 1 | 2010-02-19T21:50:49Z | [
"python",
"django",
"django-models",
"wiki"
] |
Problem with asyn icmp ping | 2,299,751 | <p>I'm writing service in python that async ping domains. So it must be able to ping many ip's at the same time. I wrote it on epoll ioloop, but have problem with packets loss.
When there are many simultaneous ICMP requests much part of replies on them didn't reach my servise. What may cause this situation and how i ca... | 1 | 2010-02-19T21:32:25Z | 2,299,927 | <p>A problem you might be having is due to the fact that ICMP is layer 3 of the OSI model and does not use a port for communication. In short, ICMP isn't really designed for this. The desired behavior is still possible but perhaps the IP Stack you are using is getting in the way and if this is on a Windows system then... | 0 | 2010-02-19T22:00:11Z | [
"python",
"ping",
"icmp"
] |
Django: When using register.inclusion_tag() where/what order is the template searched for? | 2,299,779 | <p>When using the <code>register.inclusion_tag()</code> shortcut on a Custom Template Tag, assuming you define the template as <code>'some_fragment.html'</code>, in what directories/order does Django try to find that template? </p>
<p>Assume as many 'defaults' as is reasonable. </p>
<p>The Custom Template Tag portion... | 0 | 2010-02-19T21:37:05Z | 2,299,816 | <p>It follows exactly the same rules <a href="http://docs.djangoproject.com/en/1.1/ref/templates/api/#loading-templates" rel="nofollow">as for any other template</a>. That is, it will use the directories specified in your <code>TEMPLATE_DIRS</code> setting in order - then, depending on the contents of your <code>TEMPLA... | 3 | 2010-02-19T21:45:09Z | [
"python",
"django",
"django-templates"
] |
why python associative map member variable is shared between objects | 2,299,801 | <p>For class A, why is aMap member variable being shared between object and object b?</p>
<pre><code>>>> class A:
... aMap = {}
>>> a = A()
>>> a.aMap["hello"] = 1
>>> b = A()
>>> b.aMap["world"] = 2
>>> c = []
>>> c.append(a)
>>> c.append(... | 1 | 2010-02-19T21:42:54Z | 2,299,830 | <p>Because you defined it as a class attribute, not instance attribute.</p>
<p>If you wish to have it as instance attribute and not be shared between instances, you have to define it like this:</p>
<pre><code>class A(object):
def __init__(self):
self.aMap = {}
</code></pre>
| 5 | 2010-02-19T21:47:37Z | [
"python"
] |
why python associative map member variable is shared between objects | 2,299,801 | <p>For class A, why is aMap member variable being shared between object and object b?</p>
<pre><code>>>> class A:
... aMap = {}
>>> a = A()
>>> a.aMap["hello"] = 1
>>> b = A()
>>> b.aMap["world"] = 2
>>> c = []
>>> c.append(a)
>>> c.append(... | 1 | 2010-02-19T21:42:54Z | 2,299,835 | <p>Because its a class attribute, not an instance attribute ("member variable").</p>
<p>To make it a instance attribute, assign it on an instance, e.g. in the constructor:</p>
<pre><code>class A:
def __init__(self):
self.aMap = {}
</code></pre>
<p>But you could also do:</p>
<pre><code>a = A()
a.aMap = {... | 3 | 2010-02-19T21:48:11Z | [
"python"
] |
why python associative map member variable is shared between objects | 2,299,801 | <p>For class A, why is aMap member variable being shared between object and object b?</p>
<pre><code>>>> class A:
... aMap = {}
>>> a = A()
>>> a.aMap["hello"] = 1
>>> b = A()
>>> b.aMap["world"] = 2
>>> c = []
>>> c.append(a)
>>> c.append(... | 1 | 2010-02-19T21:42:54Z | 2,299,853 | <p>Because you are effectively defining a <a href="http://www.python.org/doc/2.5.2/tut/node11.html#SECTION0011320000000000000000" rel="nofollow">class variable</a> instead of an <a href="http://www.python.org/doc/2.5.2/tut/node11.html#SECTION0011330000000000000000" rel="nofollow">instance variable</a>.</p>
<p>To defin... | 0 | 2010-02-19T21:51:17Z | [
"python"
] |
How do I add five numbers from user input in Python? | 2,299,890 | <p>As a practice exercise, I am trying to get five numbers from a user and return the sum of all five number using a while loop. I managed to gather the five numbers, but the sum is not provided by my code (I get a number, but it is always double the last number). I believe the issue is with my use of +=.</p>
<pre><... | 0 | 2010-02-19T21:56:23Z | 2,299,896 | <p>This should be better.</p>
<pre><code>x = 0
s = 0
while x < 5:
x += 1
s += (int(raw_input("Enter a number: ")))
print s
</code></pre>
<p>You were putting one of the results on to the sum of all results and lost the previous ones.</p>
| 8 | 2010-02-19T21:57:01Z | [
"python"
] |
How do I add five numbers from user input in Python? | 2,299,890 | <p>As a practice exercise, I am trying to get five numbers from a user and return the sum of all five number using a while loop. I managed to gather the five numbers, but the sum is not provided by my code (I get a number, but it is always double the last number). I believe the issue is with my use of +=.</p>
<pre><... | 0 | 2010-02-19T21:56:23Z | 2,299,959 | <p>Gruszczy already solved your main problem, but here is some advice relevant to your code.</p>
<p>First, it's easier to do a <code>for</code> loop rather than keep track of iterations in a <code>while</code>:</p>
<pre><code>s = 0
for i in range(5):
s += int(raw_input('Enter a number: '))
</code></pre>
<p>Second,... | 11 | 2010-02-19T22:06:21Z | [
"python"
] |
How do I add five numbers from user input in Python? | 2,299,890 | <p>As a practice exercise, I am trying to get five numbers from a user and return the sum of all five number using a while loop. I managed to gather the five numbers, but the sum is not provided by my code (I get a number, but it is always double the last number). I believe the issue is with my use of +=.</p>
<pre><... | 0 | 2010-02-19T21:56:23Z | 17,676,572 | <p>Adding str or int by user_input & then printing the result -
<a href="http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/io.html#numbers-and-strings-of-digits" rel="nofollow">Adding 2 or more no's from users input</a></p>
<p>example from the abv link</p>
<pre><code>'''Two numeric inputs, explicit sum'''
x ... | 0 | 2013-07-16T12:30:30Z | [
"python"
] |
How do I add five numbers from user input in Python? | 2,299,890 | <p>As a practice exercise, I am trying to get five numbers from a user and return the sum of all five number using a while loop. I managed to gather the five numbers, but the sum is not provided by my code (I get a number, but it is always double the last number). I believe the issue is with my use of +=.</p>
<pre><... | 0 | 2010-02-19T21:56:23Z | 20,275,432 | <pre><code>x = 0
s = 0
while x < 5:
x += 1
s += (int(raw_input("Enter a number: ")))
print s
</code></pre>
| 0 | 2013-11-28T22:09:14Z | [
"python"
] |
retrieving the keys of all variables on an object | 2,300,383 | <p>If I had:</p>
<pre><code>class A(object):
varA = 1
inst = A()
</code></pre>
<p>Then how would I retrieve the keys of all variables on inst? I'd want something like <code>["varA"]</code></p>
<p>So far, I've gotten this:</p>
<pre><code>vars(inst.__class__).keys() #returns ['__dict__', '__weakref__', '__module... | 0 | 2010-02-19T23:45:31Z | 2,300,393 | <p>There is a python module, called <code>inspect</code> for runtime introspection. Maybe <a href="http://docs.python.org/library/inspect.html#inspect.getmembers" rel="nofollow"><code>inspect.getmembers</code></a> can help you ...</p>
| 1 | 2010-02-19T23:48:51Z | [
"python",
"class",
"multiple-inheritance"
] |
If you are really good at Python and Regex, please help fix function | 2,300,563 | <pre><code>def boldword(text, needle):
return mark_safe(re.compile(r"\b(%s)\b" % "|".join(map(re.escape, needle.split(' '))), re.I).sub(r'<strong>\1</strong>', text))
</code></pre>
<p>This is currently my function to bold a string text given a needle. (Like Google...they bold the text for you when you ... | 1 | 2010-02-20T00:39:51Z | 2,300,683 | <p>What your description told me is that A) The input variable isn't being correctly split by spaces and B) It's not being properly escaped.</p>
<p>I think it may be an instance of under parenthesized expressions:</p>
<p>Try this:</p>
<pre><code>return mark_safe(re.compile((r"\b(%s)\b" % ("|".join(map(re.escape, nee... | 1 | 2010-02-20T01:35:09Z | [
"python",
"regex"
] |
If you are really good at Python and Regex, please help fix function | 2,300,563 | <pre><code>def boldword(text, needle):
return mark_safe(re.compile(r"\b(%s)\b" % "|".join(map(re.escape, needle.split(' '))), re.I).sub(r'<strong>\1</strong>', text))
</code></pre>
<p>This is currently my function to bold a string text given a needle. (Like Google...they bold the text for you when you ... | 1 | 2010-02-20T00:39:51Z | 2,300,722 | <p>Here's some duct tape I added to help you pass the cases you listed -- this problem is actually pretty interesting. There are probably some cases that won't be correct (e.g. Google will highlight <code>duck</code> if you search for <code>ducks</code>, this will only work for <code>duck's</code>).</p>
<p>Without a ... | 1 | 2010-02-20T01:55:53Z | [
"python",
"regex"
] |
If you are really good at Python and Regex, please help fix function | 2,300,563 | <pre><code>def boldword(text, needle):
return mark_safe(re.compile(r"\b(%s)\b" % "|".join(map(re.escape, needle.split(' '))), re.I).sub(r'<strong>\1</strong>', text))
</code></pre>
<p>This is currently my function to bold a string text given a needle. (Like Google...they bold the text for you when you ... | 1 | 2010-02-20T00:39:51Z | 2,300,769 | <p>Your biggest problem seems to be the word boundaries. If the tokens you're searching for can begin or end with non-word characters (e.g., <code>(video)</code>), enclosing the regex in <code>\b</code> prevents matching. They also prevent matching of two or more contiguous tokens (e.g., <code>theshow</code> in <code... | 2 | 2010-02-20T02:17:54Z | [
"python",
"regex"
] |
Installing Mercurial 1.4.3 - Python Requirement? | 2,300,636 | <p>Is it ok if I install Python 2.6.4 instead of the 2.4 requirement listed on the <a href="http://mercurial.selenic.com/" rel="nofollow">Mercurial website</a>?</p>
<p>I'm fairly new to Mercurial and Python. My general impression of Python is that newer versions break compatibility with older versions.</p>
<p>If Pyth... | 2 | 2010-02-20T01:12:18Z | 2,300,647 | <p>2.4 is a minimum requirement. 2.6.4 is fine.</p>
| 4 | 2010-02-20T01:15:48Z | [
"python",
"mercurial"
] |
Basic Django - Custom Managers | 2,300,737 | <p>I'm going through the <a href="http://www.djangobook.com/en/2.0/chapter10/" rel="nofollow">Django book</a> and I'm currently on <a href="http://www.djangobook.com/en/2.0/chapter10/" rel="nofollow">chapter 10</a>. I'm having a problem understanding the third line in this fragment of code:</p>
<pre><code>class DahlBo... | 1 | 2010-02-20T02:02:30Z | 2,300,785 | <p>No, <code>self</code> is an instance of <code>DahlBookManager</code>. <code>super()</code> uses the class to handle things like MRO, inheritance, etc.</p>
| 0 | 2010-02-20T02:21:07Z | [
"python",
"django"
] |
Basic Django - Custom Managers | 2,300,737 | <p>I'm going through the <a href="http://www.djangobook.com/en/2.0/chapter10/" rel="nofollow">Django book</a> and I'm currently on <a href="http://www.djangobook.com/en/2.0/chapter10/" rel="nofollow">chapter 10</a>. I'm having a problem understanding the third line in this fragment of code:</p>
<pre><code>class DahlBo... | 1 | 2010-02-20T02:02:30Z | 2,300,799 | <p>This is about the builtin Super() function in Python.</p>
<p>You can get a reference here: <a href="http://docs.python.org/library/functions.html" rel="nofollow">http://docs.python.org/library/functions.html</a></p>
<blockquote>
<p>If the second argument is omitted, the
super object returned is unbound.</p>
</... | 0 | 2010-02-20T02:27:50Z | [
"python",
"django"
] |
Problem in calculating checksum : casting int to signed int32 | 2,300,740 | <p>I need to convert the following c code (to calculate checksum for a file) to python. I had written, the corresponding code in python but the result didn't match the c version. The problem was that python autmatically promotes int to long whenever overflow occurs and this results in wrong checksums.</p>
<p>Any idea ... | 3 | 2010-02-20T02:03:33Z | 2,300,779 | <p>Use <a href="http://docs.scipy.org/doc/numpy/user/basics.types.html?highlight=int32#array-types-and-conversions-between-types" rel="nofollow"><code>numpy.int32</code></a> or <code>numpy.uint32</code> if you need to restrict the range. Or mod it by <code>1 << 32</code> after operations that could "overflow".</p... | 2 | 2010-02-20T02:19:45Z | [
"python",
"casting",
"checksum"
] |
Get the nth item of a generator in Python | 2,300,756 | <p>Is there a more syntactically concise way of writing the following?</p>
<pre><code>gen = (i for i in xrange(10))
index = 5
for i, v in enumerate(gen):
if i is index:
return v
</code></pre>
<p>It seems almost natural that a generator should have a <code>gen[index]</code> expression, that acts as a list,... | 25 | 2010-02-20T02:11:36Z | 2,300,764 | <p>Perhaps you should elaborate more on a actual use case.</p>
<pre><code>>>> gen = xrange(10)
>>> ind=5
>>> gen[ind]
5
</code></pre>
| 0 | 2010-02-20T02:15:11Z | [
"python",
"generator"
] |
Get the nth item of a generator in Python | 2,300,756 | <p>Is there a more syntactically concise way of writing the following?</p>
<pre><code>gen = (i for i in xrange(10))
index = 5
for i, v in enumerate(gen):
if i is index:
return v
</code></pre>
<p>It seems almost natural that a generator should have a <code>gen[index]</code> expression, that acts as a list,... | 25 | 2010-02-20T02:11:36Z | 2,300,766 | <p>one method would be to use <code>itertools.islice</code></p>
<pre><code>>>> next(itertools.islice(xrange(10), 5, 5 + 1))
5
</code></pre>
| 24 | 2010-02-20T02:15:36Z | [
"python",
"generator"
] |
Get the nth item of a generator in Python | 2,300,756 | <p>Is there a more syntactically concise way of writing the following?</p>
<pre><code>gen = (i for i in xrange(10))
index = 5
for i, v in enumerate(gen):
if i is index:
return v
</code></pre>
<p>It seems almost natural that a generator should have a <code>gen[index]</code> expression, that acts as a list,... | 25 | 2010-02-20T02:11:36Z | 2,300,768 | <p>You could do this, using <code>count</code> as an example generator:</p>
<pre><code>from itertools import islice, count
next(islice(count(), n, n+1))
</code></pre>
| 12 | 2010-02-20T02:17:31Z | [
"python",
"generator"
] |
Manipulating dates in the datastore | 2,300,759 | <p>I've recently been playing around with Google's AppEngine and I seem to have gotten stuck. I'm trying to create a query that selects posts that are before a certain date (in this case, the date is now - 1 day). I've tried a few different methods in order to accomplish this, but none have worked. One of which involve... | 0 | 2010-02-20T02:12:51Z | 2,301,806 | <p>What happens if you build your query <a href="http://code.google.com/appengine/docs/python/datastore/queryclass.html" rel="nofollow">using methods</a>?</p>
<pre><code>query = Post.all()
query.filter('date < ', datetime.datetime - 84600)
results = query.fetch(limit=10)
</code></pre>
| 1 | 2010-02-20T10:15:18Z | [
"python",
"database",
"google-app-engine"
] |
Manipulating dates in the datastore | 2,300,759 | <p>I've recently been playing around with Google's AppEngine and I seem to have gotten stuck. I'm trying to create a query that selects posts that are before a certain date (in this case, the date is now - 1 day). I've tried a few different methods in order to accomplish this, but none have worked. One of which involve... | 0 | 2010-02-20T02:12:51Z | 2,302,747 | <p>You need to move the math outside of the query:</p>
<pre><code>db.GqlQuery("SELECT __key__ FROM Post WHERE date < :1 LIMIT 10, ORDER BY date DESC", (time.time() - 84600))
</code></pre>
| 1 | 2010-02-20T16:00:42Z | [
"python",
"database",
"google-app-engine"
] |
Using list.reverse() on a subset of a list. "NoneType" object is not iterable | 2,300,872 | <p>So, I'm trying to append to one list the reverse of a subset of another list. For some reason, the interpreter doesn't seem to be liking it. Here's what I'm doing.</p>
<pre><code>list1.extend(list2[someInt:someOtherInt].reverse())
</code></pre>
<p>Why is this not legit? It seems reasonable to me..</p>
| 2 | 2010-02-20T03:09:44Z | 2,300,875 | <p><code>list</code> methods operate in-place, which means that they return <code>None</code>.</p>
| 5 | 2010-02-20T03:10:51Z | [
"python",
"list"
] |
Using list.reverse() on a subset of a list. "NoneType" object is not iterable | 2,300,872 | <p>So, I'm trying to append to one list the reverse of a subset of another list. For some reason, the interpreter doesn't seem to be liking it. Here's what I'm doing.</p>
<pre><code>list1.extend(list2[someInt:someOtherInt].reverse())
</code></pre>
<p>Why is this not legit? It seems reasonable to me..</p>
| 2 | 2010-02-20T03:09:44Z | 2,300,879 | <p>In addition to Ignacio's answer, here's a solution. Try:</p>
<pre><code>list1.extend(reversed(list2[someInt:someOtherInt]))
</code></pre>
<p>Alternatively, you can use a slice with reversed indexes, but be careful with off-by-one errors!</p>
<pre><code>list1.extend(list2[someOtherInt - 1: someInt - 1: -1])
</code... | 3 | 2010-02-20T03:12:21Z | [
"python",
"list"
] |
how do i set my 'Connect URL'and 'Canvas Callback URL' in facebook | 2,300,911 | <p><img src="http://omploader.org/vM2x6ag" alt="alt text"></p>
<p><img src="http://omploader.org/vM2x6cA" alt="alt text"></p>
<p><img src="http://omploader.org/vM2x6cQ" alt="alt text"></p>
| -3 | 2010-02-20T03:23:58Z | 2,301,567 | <p>You can't set it to 127.0.0.1, that's an address that's only visible from your local machine. You need to use an address that Facebook itself can see. You can use your own computer's external IP address, but you'll need to configure your router to forward port 80 to your machine.</p>
| 1 | 2010-02-20T08:20:33Z | [
"javascript",
"python",
"django",
"facebook",
"pyfacebook"
] |
Returning a list from a function in Python | 2,300,963 | <p>I'm creating a game for my sister, and I want a function to return a list variable, so I can pass it to another variable.</p>
<p>The relevant code is as follows:</p>
<pre><code>def startNewGame():
while 1:
#Introduction:
print
print """Hello,
You will now be guided through the setup pro... | 2 | 2010-02-20T03:49:49Z | 2,300,985 | <p>First all, i must say you are writing good code for a beginner, though you can improve startNewGame by writing a function, for getting user input in a loop, instead of writing same code again and again.</p>
<p>I copied your code and it runs without problem, though i did a small change</p>
<p>you are doing </p>
<p... | 5 | 2010-02-20T04:04:12Z | [
"python"
] |
Returning a list from a function in Python | 2,300,963 | <p>I'm creating a game for my sister, and I want a function to return a list variable, so I can pass it to another variable.</p>
<p>The relevant code is as follows:</p>
<pre><code>def startNewGame():
while 1:
#Introduction:
print
print """Hello,
You will now be guided through the setup pro... | 2 | 2010-02-20T03:49:49Z | 2,302,024 | <p>At first I thought you were just calling a function that didn't exist because your "relevant code" snippet shows us the definition of startNewGame() followed by this:</p>
<pre><code>welcomeMessage()
MCreatePH = startGame()
myPotatoHead = PotatoHead(MCreatePH)
</code></pre>
<p>However, then I read the full code a... | 0 | 2010-02-20T11:34:05Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.