title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Python, Perl And C/C++ With GUI | 1,628,001 | <p>I'm now thinking, is it possible to integrate Python, Perl and C/C++ and also doing a GUI application with this very nice mix of languages?</p>
| 1 | 2009-10-27T00:04:53Z | 1,628,011 | <p>Anything is "possible", but whether it is necessary or beneficial is debatable and highly depends on your requirements. Don't mix if you don't need to. Use the language that best fits the domain or target requirements. </p>
<p>I can't think of a scenario where one needs to mix Python and Perl as their domain is lar... | 5 | 2009-10-27T00:07:38Z | [
"c++",
"python",
"c",
"perl",
"integration"
] |
Python, Perl And C/C++ With GUI | 1,628,001 | <p>I'm now thinking, is it possible to integrate Python, Perl and C/C++ and also doing a GUI application with this very nice mix of languages?</p>
| 1 | 2009-10-27T00:04:53Z | 1,628,012 | <p>Everything is possible - but why add two and a half more levels of complexity?</p>
| 1 | 2009-10-27T00:07:42Z | [
"c++",
"python",
"c",
"perl",
"integration"
] |
Python, Perl And C/C++ With GUI | 1,628,001 | <p>I'm now thinking, is it possible to integrate Python, Perl and C/C++ and also doing a GUI application with this very nice mix of languages?</p>
| 1 | 2009-10-27T00:04:53Z | 1,628,013 | <p>Python & Perl? together?</p>
<p>I can only think of an editor.</p>
| 1 | 2009-10-27T00:07:54Z | [
"c++",
"python",
"c",
"perl",
"integration"
] |
Python, Perl And C/C++ With GUI | 1,628,001 | <p>I'm now thinking, is it possible to integrate Python, Perl and C/C++ and also doing a GUI application with this very nice mix of languages?</p>
| 1 | 2009-10-27T00:04:53Z | 1,628,022 | <p>Well, there is <a href="http://search.cpan.org/dist/Wx/" rel="nofollow">Wx</a>, <a href="http://search.cpan.org/perldoc/Inline%3A%3APython" rel="nofollow">Inline::Python</a> and <a href="http://search.cpan.org/perldoc/Inline%3A%3AC" rel="nofollow">Inline::C</a>, but the question is <strong>why?</strong></p>
| 9 | 2009-10-27T00:10:25Z | [
"c++",
"python",
"c",
"perl",
"integration"
] |
Python, Perl And C/C++ With GUI | 1,628,001 | <p>I'm now thinking, is it possible to integrate Python, Perl and C/C++ and also doing a GUI application with this very nice mix of languages?</p>
| 1 | 2009-10-27T00:04:53Z | 1,628,043 | <p>There's always <a href="http://www.parrot.org/" rel="nofollow">Parrot</a>. Here's the <a href="http://en.wikipedia.org/wiki/Parrot%5Fvirtual%5Fmachine" rel="nofollow">Wikipedia page</a>. It's a vm to allow you access your favorite libraries from different languages in one application.</p>
| 3 | 2009-10-27T00:15:49Z | [
"c++",
"python",
"c",
"perl",
"integration"
] |
Using the same handler for multiple wx.TextCtrls? | 1,628,010 | <p>I'm having a bit of trouble with a panel that has two wxPython TextCtrls in it. I want either an EVT_CHAR or EVT_KEY_UP handler bound to both controls, and I want to be able to tell which TextCtrl generated the event. I would think that event.Id would tell me this, but in the following sample code it's always 0. Any... | 0 | 2009-10-27T00:07:17Z | 1,628,394 | <p>You could try <code>event.GetId()</code> or <code>event.GetEventObject()</code> and see if either of these work.</p>
<p>Another approach to this is to use lambda or functools.partial to effectively pass a parameter to the handler. So, for example, sub in the lines below into your program:</p>
<pre><code> s... | 4 | 2009-10-27T02:05:13Z | [
"python",
"wxpython"
] |
Python Infinity - Any caveats? | 1,628,026 | <p>So Python has positive and negative infinity:</p>
<pre><code>float("inf"), float("-inf")
</code></pre>
<p>This just seems like the type of feature that has to have some caveat. Is there anything I should be aware of? </p>
| 133 | 2009-10-27T00:12:06Z | 1,628,075 | <p>So does <a href="http://www.schweikhardt.net/identifiers.html" rel="nofollow">C99</a>.</p>
<p>The IEEE 754 floating point representation used by all modern processors has several special bit patterns reserved for positive infinity (sign=0, exp=~0, frac=0), negative infinity (sign=1, exp=~0, frac=0), and many NaN (N... | 3 | 2009-10-27T00:25:05Z | [
"python"
] |
Python Infinity - Any caveats? | 1,628,026 | <p>So Python has positive and negative infinity:</p>
<pre><code>float("inf"), float("-inf")
</code></pre>
<p>This just seems like the type of feature that has to have some caveat. Is there anything I should be aware of? </p>
| 133 | 2009-10-27T00:12:06Z | 1,628,105 | <p>You can still get not-a-number (NaN) values from simple arithmetic involving <code>inf</code>:</p>
<pre><code>>>> 0 * float("inf")
nan
</code></pre>
<p>Note that you will normally <em>not</em> get an <code>inf</code> value through usual arithmetic calculations:</p>
<pre><code>>>> 2.0**2
4.0
>... | 79 | 2009-10-27T00:31:36Z | [
"python"
] |
Python Infinity - Any caveats? | 1,628,026 | <p>So Python has positive and negative infinity:</p>
<pre><code>float("inf"), float("-inf")
</code></pre>
<p>This just seems like the type of feature that has to have some caveat. Is there anything I should be aware of? </p>
| 133 | 2009-10-27T00:12:06Z | 1,628,113 | <p><a href="https://docs.python.org/2/library/decimal.html">Python's implementation</a> follows the <a href="http://en.wikipedia.org/wiki/IEEE_754-1985">IEEE-754 standard</a> pretty well, which you can use as a guidance, but it relies on the underlying system it was compiled on, so <a href="http://www.python.org/dev/pe... | 76 | 2009-10-27T00:33:01Z | [
"python"
] |
Can someone explain this unexpected Python import behavior? | 1,628,085 | <p>I've run into some behavior from Python 2.6.1 that I didn't expect. Here is some trivial code to reproduce the problem:</p>
<pre><code>---- ControlPointValue.py ------
class ControlPointValue:
def __init__(self):
pass
---- ControlPointValueSet.py ----
import ControlPointValue
---- main.py --------------... | 0 | 2009-10-27T00:27:07Z | 1,628,124 | <p>I don't think it's unexpected. What you are basically doing is:</p>
<p>1) the first import in main.py imports the contents of ControlPointValue module into the global namespace. this produces a class bound to that name.</p>
<p>2) the second import in main.py imports the contents of ControlPointValueSet module into... | 10 | 2009-10-27T00:34:53Z | [
"python",
"import"
] |
Can someone explain this unexpected Python import behavior? | 1,628,085 | <p>I've run into some behavior from Python 2.6.1 that I didn't expect. Here is some trivial code to reproduce the problem:</p>
<pre><code>---- ControlPointValue.py ------
class ControlPointValue:
def __init__(self):
pass
---- ControlPointValueSet.py ----
import ControlPointValue
---- main.py --------------... | 0 | 2009-10-27T00:27:07Z | 1,628,310 | <p>In addition to the other suggestions about star imports, don't name your module and your class the same. Follow <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">pep8's suggestions</a> and give your modules short all lower case names and name your classes LikeThis. E.g.</p>
<pre><code>---- control... | 4 | 2009-10-27T01:37:12Z | [
"python",
"import"
] |
paths not being consistent python django | 1,628,129 | <p>I'm trying to import sorl-thumbnail into my app in django. Now the way that I have the site set up, using mod_wsgi on CentOS 5 with cpanel, the path for the apps must have the project name when importing... which is a pain.</p>
<p>Obviously this is a cause of concern with portability of the app. I'm importing sorl-... | 1 | 2009-10-27T00:36:15Z | 1,628,517 | <p>You shouldn't need to use the project name when importing - just make sure that the apps are somewhere on your python path. Something along the lines of:</p>
<pre><code>sys.path.append('/etc/django/domains/mydomain.com/myproject/')
</code></pre>
<p>... in your .wsgi file should do it (with the path to your own pro... | 3 | 2009-10-27T02:46:11Z | [
"python",
"django",
"sorl-thumbnail",
"import"
] |
python attribute lookup without any descriptor magic? | 1,628,137 | <p>I've started to use the python descriptor protocol more extensively in the code I've been writing. Typically, the default python lookup magic is what I want to happen, but sometimes I'm finding I want to get the descriptor object itself instead the results of its <code>__get__</code> method. Wanting to know the typ... | 2 | 2009-10-27T00:38:26Z | 1,629,912 | <p>Most descriptors do their job when accessed as instance attribute only. So it's convenient to return itself when it's accessed for class:</p>
<pre><code>class FixedValueProperty(object):
def __init__(self, value):
self.value = value
def __get__(self, inst, cls):
if inst is None:
... | 9 | 2009-10-27T10:27:14Z | [
"python",
"python-datamodel",
"descriptor"
] |
python attribute lookup without any descriptor magic? | 1,628,137 | <p>I've started to use the python descriptor protocol more extensively in the code I've been writing. Typically, the default python lookup magic is what I want to happen, but sometimes I'm finding I want to get the descriptor object itself instead the results of its <code>__get__</code> method. Wanting to know the typ... | 2 | 2009-10-27T00:38:26Z | 34,985,260 | <p>The above method </p>
<pre><code>class FixedValueProperty(object):
def __init__(self, value):
self.value = value
def __get__(self, inst, cls):
if inst is None:
return self
return self.value
</code></pre>
<p>Is a great method whenever you control the code of the property,... | 0 | 2016-01-25T04:42:52Z | [
"python",
"python-datamodel",
"descriptor"
] |
chaining queries together in Django | 1,628,162 | <p>I have a query that gets me 32 avatar images from my avatar application:</p>
<pre><code>newUserAv = Avatar.objects.filter(valid=True)[:32]
</code></pre>
<p>I'd like to combine this with a query to django's Auth user model, so I can get the last the last 32 people, who have avatar images, sorted by the date joined.... | 0 | 2009-10-27T00:48:12Z | 1,628,182 | <p>It's not possible to combine queries on two different base models. Django won't let you do this (it'll throw an error telling you exactly that).</p>
<p>However, if you have a foreignkey from one model to the other, then adding select_related() to your query will fetch the related objects into memory in a single DB ... | 0 | 2009-10-27T00:52:46Z | [
"python",
"django",
"django-models"
] |
chaining queries together in Django | 1,628,162 | <p>I have a query that gets me 32 avatar images from my avatar application:</p>
<pre><code>newUserAv = Avatar.objects.filter(valid=True)[:32]
</code></pre>
<p>I'd like to combine this with a query to django's Auth user model, so I can get the last the last 32 people, who have avatar images, sorted by the date joined.... | 0 | 2009-10-27T00:48:12Z | 1,628,472 | <p>Either you put a field in your own User class (you might have to subclass User or compose with <code>django.contrib.auth.models.User</code>) that indicates that the User has an avatar. Than you can make your query easily.</p>
<p>Or do something like that:</p>
<pre><code>from django.utils.itercompat import groupby
... | 2 | 2009-10-27T02:31:08Z | [
"python",
"django",
"django-models"
] |
The advantages of having static function like len(), max(), and min() over inherited method calls | 1,628,222 | <p>i am a python newbie, and i am not sure why python implemented len(obj), max(obj), and min(obj) as a static like functions (i am from the java language) over obj.len(), obj.max(), and obj.min()</p>
<p>what are the advantages and disadvantages (other than obvious inconsistency) of having len()... over the method cal... | 8 | 2009-10-27T01:02:37Z | 1,628,285 | <p>It emphasizes the capabilities of an object, not its methods or type. Capabilites are declared by "helper" functions such as <code>__iter__</code> and <code>__len__</code> but they don't make up the interface. The interface is in the builtin functions, and beside this also in the buit-in operators like + and [] for ... | 2 | 2009-10-27T01:26:47Z | [
"python",
"language-design"
] |
The advantages of having static function like len(), max(), and min() over inherited method calls | 1,628,222 | <p>i am a python newbie, and i am not sure why python implemented len(obj), max(obj), and min(obj) as a static like functions (i am from the java language) over obj.len(), obj.max(), and obj.min()</p>
<p>what are the advantages and disadvantages (other than obvious inconsistency) of having len()... over the method cal... | 8 | 2009-10-27T01:02:37Z | 1,628,293 | <p>Actually, those aren't "static" methods in the way you are thinking about them. They are <a href="http://docs.python.org/library/functions.html" rel="nofollow">built-in functions</a> that really just alias to certain methods on python objects that implement them.</p>
<pre><code>>>> class Foo(object):
... ... | 3 | 2009-10-27T01:29:42Z | [
"python",
"language-design"
] |
The advantages of having static function like len(), max(), and min() over inherited method calls | 1,628,222 | <p>i am a python newbie, and i am not sure why python implemented len(obj), max(obj), and min(obj) as a static like functions (i am from the java language) over obj.len(), obj.max(), and obj.min()</p>
<p>what are the advantages and disadvantages (other than obvious inconsistency) of having len()... over the method cal... | 8 | 2009-10-27T01:02:37Z | 1,628,300 | <p>The big advantage is that built-in functions (and operators) can apply extra logic when appropriate, beyond simply calling the special methods. For example, <code>min</code> can look at several arguments and apply the appropriate inequality checks, or it can accept a single iterable argument and proceed similarly; ... | 15 | 2009-10-27T01:30:53Z | [
"python",
"language-design"
] |
The advantages of having static function like len(), max(), and min() over inherited method calls | 1,628,222 | <p>i am a python newbie, and i am not sure why python implemented len(obj), max(obj), and min(obj) as a static like functions (i am from the java language) over obj.len(), obj.max(), and obj.min()</p>
<p>what are the advantages and disadvantages (other than obvious inconsistency) of having len()... over the method cal... | 8 | 2009-10-27T01:02:37Z | 1,628,318 | <p>I thought the reason was so these basic operations could be done on iterators with the same interface as containers. However, it actually doesn't work with len:</p>
<pre><code>def foo():
for i in range(10):
yield i
print len(foo())
</code></pre>
<p>... fails with TypeError. len() won't consume and co... | 1 | 2009-10-27T01:40:56Z | [
"python",
"language-design"
] |
SAS and Web Data | 1,628,372 | <p>I have been taking a few graduate classes with a professor I like alot and she raves about SAS all of the time. I "grew up" learning stats using SPSS, and with their recent decisions to integrate their stats engine with R and Python, I find it difficult to muster up the desire to learn anything else. I am not that... | 1 | 2009-10-27T01:56:29Z | 1,628,669 | <p>yes. sas 9.2 can interact with soap and restful apis. i haven't had much success with twitter. i have had some success with google spreadsheets (in sas 9.1.3) and i've seen code to pull google analytics (in sas 9.2).</p>
<p>as with python and r, you can write the code in any text editor, but you'll need to have sas... | 5 | 2009-10-27T03:46:43Z | [
"python",
"statistics",
"sas"
] |
SAS and Web Data | 1,628,372 | <p>I have been taking a few graduate classes with a professor I like alot and she raves about SAS all of the time. I "grew up" learning stats using SPSS, and with their recent decisions to integrate their stats engine with R and Python, I find it difficult to muster up the desire to learn anything else. I am not that... | 1 | 2009-10-27T01:56:29Z | 1,631,022 | <p>Incidentally, SAS is now offering integration with R.
<a href="http://support.sas.com/rnd/app/studio/Rinterface2.html" rel="nofollow">http://support.sas.com/rnd/app/studio/Rinterface2.html</a></p>
<p>There are all sorts of ways to get data off the web. One example is to use the url access methods on filename stat... | 6 | 2009-10-27T14:02:12Z | [
"python",
"statistics",
"sas"
] |
Real time update of relative leaderboard for each user among friends | 1,628,562 | <p>Ive been working on a feature of my application to implement a leaderboard - basically stack rank users according to their score. Im currently tracking the score on an individual basis. My thought is that this leaderboard should be relative instead of absolute i.e. instead of having the top 10 highest scoring user... | 0 | 2009-10-27T03:07:08Z | 1,628,703 | <p>If writes are very rare compared to reads (a key assumption in most key-value stores, and not just in those;-), then you might prefer to take a time hit when you need to update scores (a write) rather than to get the relative leaderboards (a read). Specifically, when a user's score change, queue up tasks for each o... | 4 | 2009-10-27T04:01:13Z | [
"python",
"google-app-engine",
"leaderboard"
] |
Real time update of relative leaderboard for each user among friends | 1,628,562 | <p>Ive been working on a feature of my application to implement a leaderboard - basically stack rank users according to their score. Im currently tracking the score on an individual basis. My thought is that this leaderboard should be relative instead of absolute i.e. instead of having the top 10 highest scoring user... | 0 | 2009-10-27T03:07:08Z | 1,633,067 | <p>There is a python library available for storing rankings:</p>
<p><a href="http://code.google.com/p/google-app-engine-ranklist/" rel="nofollow">http://code.google.com/p/google-app-engine-ranklist/</a></p>
| 1 | 2009-10-27T19:18:14Z | [
"python",
"google-app-engine",
"leaderboard"
] |
Is it possible access other webpages from within another page | 1,628,564 | <p>Basically, what I'm trying to do is simply make a small script that accesses finds the most recent post in a forum and pulls some text or an image out of it. I have this working in python, using the htmllib module and some regex. But, the script still isn't very convenient as is, it would be much nicer if I could ... | 1 | 2009-10-27T03:07:34Z | 1,628,574 | <p>You can embed Python. The most straightforward way would be to use the <a href="http://docs.python.org/library/cgi.html" rel="nofollow">cgi</a> module. If the script will be run often and you're using Apache it would be more efficient to use <a href="http://www.modpython.org/" rel="nofollow">mod_python</a> or <a hre... | 0 | 2009-10-27T03:11:28Z | [
"javascript",
"jquery",
"python"
] |
Is it possible access other webpages from within another page | 1,628,564 | <p>Basically, what I'm trying to do is simply make a small script that accesses finds the most recent post in a forum and pulls some text or an image out of it. I have this working in python, using the htmllib module and some regex. But, the script still isn't very convenient as is, it would be much nicer if I could ... | 1 | 2009-10-27T03:07:34Z | 1,628,598 | <p>There are two general approaches:</p>
<ul>
<li>Modify your Python code so that it runs as a CGI (or WSGI or whatever) module and generate the page of interest by running some <em>server side</em> code.</li>
<li>Use Javascript with jQuery to load the content of interest by running some <em>client side</em> code.</li... | 1 | 2009-10-27T03:19:23Z | [
"javascript",
"jquery",
"python"
] |
Is it possible access other webpages from within another page | 1,628,564 | <p>Basically, what I'm trying to do is simply make a small script that accesses finds the most recent post in a forum and pulls some text or an image out of it. I have this working in python, using the htmllib module and some regex. But, the script still isn't very convenient as is, it would be much nicer if I could ... | 1 | 2009-10-27T03:07:34Z | 1,628,672 | <p>As Greg mentions, an Ajax solution will not work "out of the box" when trying to load from remote servers.</p>
<p>If, however, you are trying to load from the <em>same</em> server, it should be fairly straightforward. I'm presenting this answer to show how this could be done using jQuery in just a few lines of code... | 3 | 2009-10-27T03:50:02Z | [
"javascript",
"jquery",
"python"
] |
How to check if a FileField has been modified in the Admin of Django? | 1,628,676 | <p>I am trying to do a model with a file that shouldn't be modified. But the comment of the file can be.</p>
<p>Here is what I did, but we cannot modify the comment.
How can I test if a new file (using the browse button) as been sent and in this case only, create a new instance of the model ? If no upload of a new fil... | 2 | 2009-10-27T03:50:49Z | 1,632,345 | <pre><code>if 'file' in form.changed_data:
"""
File is changed
"""
raise forms.ValidationError("No, don't change the file because blah blah")
else:
"""
File is not changed
"""
</code></pre>
| 5 | 2009-10-27T17:18:06Z | [
"python",
"django",
"django-admin",
"django-forms",
"django-file-upload"
] |
Python Package For Multi-Threaded Spider w/ Proxy Support? | 1,628,766 | <p>Instead of just using urllib does anyone know of the most efficient package for fast, multithreaded downloading of URLs that can operate through http proxies? I know of a few such as Twisted, Scrapy, libcurl etc. but I don't know enough about them to make a decision or even if they can use proxies.. Anyone know of t... | 1 | 2009-10-27T04:23:46Z | 1,630,523 | <p>is's simple to implement this in python.</p>
<blockquote>
<p>The urlopen() function works
transparently with proxies which do
not require authentication. In a Unix
or Windows environment, set the
http_proxy, ftp_proxy or gopher_proxy
environment variables to a URL that
identifies the proxy server befo... | 16 | 2009-10-27T12:36:13Z | [
"python",
"proxy",
"multithreading",
"web-crawler",
"pool"
] |
Python Package For Multi-Threaded Spider w/ Proxy Support? | 1,628,766 | <p>Instead of just using urllib does anyone know of the most efficient package for fast, multithreaded downloading of URLs that can operate through http proxies? I know of a few such as Twisted, Scrapy, libcurl etc. but I don't know enough about them to make a decision or even if they can use proxies.. Anyone know of t... | 1 | 2009-10-27T04:23:46Z | 5,803,567 | <p>usually proxies filter websites categorically based on how the website was created. It is difficult to transmit data through proxies based on categories. Eg youtube is classified as audio/video streams therefore youtube is blocked in some places espically schools.
If you want to bypass proxies and get the data off a... | 1 | 2011-04-27T11:48:09Z | [
"python",
"proxy",
"multithreading",
"web-crawler",
"pool"
] |
Trace/BPT trap when calling urllib.urlopen | 1,628,916 | <p>For some reason I'm getting a Trace/BPT trap error when calling <code>urllib.urlopen</code>. I've tried both <code>urllib</code> and <code>urllib2</code> with identical results. Here is the code which throws the error:</p>
<pre><code>def get_url(url):
from urllib2 import urlopen
if not url or not url.starts... | 2 | 2009-10-27T05:32:50Z | 1,629,052 | <p>Are you running this under OS X 10.6? Apparently threads and importing modules for the first time does not play well together there. See if you can't import urllib2 outside of the thread?</p>
<p>There are a few more details in the following thread: <a href="http://stackoverflow.com/questions/1540835/trace-bpt-trap-... | 2 | 2009-10-27T06:32:36Z | [
"python",
"trace",
"urllib2",
"urllib",
"web.py"
] |
Trace/BPT trap when calling urllib.urlopen | 1,628,916 | <p>For some reason I'm getting a Trace/BPT trap error when calling <code>urllib.urlopen</code>. I've tried both <code>urllib</code> and <code>urllib2</code> with identical results. Here is the code which throws the error:</p>
<pre><code>def get_url(url):
from urllib2 import urlopen
if not url or not url.starts... | 2 | 2009-10-27T05:32:50Z | 1,724,554 | <p>Adding the following lines to the top of the main file solved the problem:</p>
<pre><code>import urllib2
urllib2.install_opener(urllib2.build_opener())
</code></pre>
<p>In other words, it is not enough to import the urllib2 module but you actually need to create the opener in the main thread.</p>
| 3 | 2009-11-12T19:00:45Z | [
"python",
"trace",
"urllib2",
"urllib",
"web.py"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 1,628,962 | <p>The line <code>k = k-1</code> does not do what you think. It has no effect. Changing <code>k</code> does not affect the loop. At each iteration, <code>k</code> is assigned to the next element of the range, so any changes you have made to <code>k</code> inside the loop will be overwritten.</p>
| 6 | 2009-10-27T05:49:26Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 1,628,981 | <p>This code is very confused, and I can't figure out exactly what you were thinking when you wrote it or what you were attempting to accomplish. The first thing I would suggest when trying to figure out how to code is to start by making your variable names extremely descriptive. This will help you get the ideas of w... | 0 | 2009-10-27T05:58:12Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 1,629,068 | <p>using a regexp :)</p>
<pre><code>#!/usr/bin/python
import re, sys
def isPrime(n):
# see http://www.noulakaz.net/weblog/2007/03/18/a-regular-expression-to-check-for-prime-numbers/
return re.match(r'^1?$|^(11+?)\1+$', '1' * n) == None
N = int(sys.argv[1]) # number of primes wanted (from command-line)
M =... | 28 | 2009-10-27T06:38:26Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 1,629,174 | <p>What you need is a Prime Sieve (a fast type of algorithm for finding primes), a very simple one is Sieve of Eratosthenes (check wikipedia) and here is an implementation in PHP <a href="http://www.scriptol.com/programming/sieve.php" rel="nofollow">http://www.scriptol.com/programming/sieve.php</a></p>
| 2 | 2009-10-27T07:11:55Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 1,629,447 | <p>What you want is something like this:</p>
<pre><code>x = int(input("Enter the number:"))
count = 0
num = 2
while count < x:
if isnumprime(x):
print x
count = count + 1
num = num + 1
</code></pre>
<p>I'll leave it up to you to implement "isnumprime()". ;)
Hint: You only need to test div... | 2 | 2009-10-27T08:38:09Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 1,630,349 | <p>Until we have N primes, take natural numbers one by one, check whether any of the so-far-collected-primes divide it. </p>
<p>If none does, "yay", we have a new prime... </p>
<p>that's it.</p>
<pre><code>>>> def generate_n_primes(N):
... primes = []
... chkthis = 2
... while len(primes) < ... | 1 | 2009-10-27T12:02:22Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 1,633,325 | <p>Using generator expressions to create a sequence of all primes and slice the 100th out of that.</p>
<pre><code>from itertools import count, islice
primes = (n for n in count(2) if all(n % d for d in range(2, n)))
print("100th prime is %d" % next(islice(primes, 99, 100)))
</code></pre>
| 2 | 2009-10-27T20:01:40Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 1,638,415 | <p>For reference, there's a pretty significant speed difference between the various stated solutions. Here is some comparison code. The solution pointed to by Lennart is called "historic", the one proposed by Ants is called "naive", and the one by RC is called "regexp."</p>
<pre><code>from sys import argv
from time im... | 12 | 2009-10-28T16:31:43Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 2,212,923 | <p>Super quick sieve implementation by <a href="http://code.activestate.com/recipes/117119/" rel="nofollow">David Eppstein</a> - takes 0.146s for the first 1000 primes on my PC:</p>
<pre><code>def gen_primes():
""" Generate an infinite sequence of prime numbers.
"""
# Maps composites to primes witnessing t... | 11 | 2010-02-06T11:28:37Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 12,454,043 | <p>Here's what I eventually came up with to print the first n primes:</p>
<pre><code>numprimes = raw_input('How many primes to print? ')
count = 0
potentialprime = 2
def primetest(potentialprime):
divisor = 2
while divisor <= potentialprime:
if potentialprime == 2:
return True
... | 4 | 2012-09-17T06:24:09Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 13,117,330 | <pre><code>n=int(input("Enter the number:: "))
for i in range(2,n):
p=i
k=0
for j in range(2,p-1):
if(p%j==0):
k=k+1
if(k==0):
print(p)
</code></pre>
| 0 | 2012-10-29T07:13:07Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 15,496,281 | <p>I am not familiar with Python so I am writing the C counter part(too lazy to write pseudo code.. :P)
To find the first n prime numbers..
// prints all the primes.. not bothering to make an array and return it etc..</p>
<pre><code>void find_first_n_primes(int n){
int count = 0;
for(int i=2;count<=n;i++){
... | 0 | 2013-03-19T09:58:28Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 16,199,011 | <p>This might help:</p>
<pre><code>def in_prime(n):
p=True
i=2
if i**2<=n:
if n%i==0:
p=False
break
if (p):
return n
</code></pre>
| 0 | 2013-04-24T17:57:35Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 16,821,158 | <pre><code>def isPrime(y):
i=2
while i < y:
if y%i == 0 :
return 0
exit()
i=i+1
return 1
x= raw_input('Enter the position 1st,2nd,..nth prime number you are looking for?: ')
z=int(x)
# for l in range(2,z)
count = 1
n = 2
while count <= z:
if isPrime(n) == 1:
if count == z:
p... | 1 | 2013-05-29T18:19:45Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 18,655,753 | <p>This might help:</p>
<pre><code>import sys
from time import time
def prime(N):
M=100
l=[]
while len(l) < N:
for i in range(M-100,M):
num = filter(lambda y :i % y == 0,(y for y in range(2 ,(i/2))))
if not num and i not in [0,1,4]:
l.append(i)
... | 0 | 2013-09-06T10:34:24Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 19,380,041 | <p>Here's a simple recursive version:</p>
<pre><code>import datetime
import math
def is_prime(n, div=2):
if div> int(math.sqrt(n)): return True
if n% div == 0:
return False
else:
div+=1
return is_prime(n,div)
now = datetime.datetime.now()
until = raw_input("How many prime num... | 0 | 2013-10-15T11:24:44Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 24,876,824 | <p>Try using while loop to check the count, that is easy. Find the code snippet below :</p>
<pre><code>i=1
count = 0;
x = int(input("Enter the number:\n"))
while (count < x):
c=0
for j in range (1, (i+1), 1):
a = i%j
if (a==0):
c = c+1
if (c==2):
print (i)
count = count+1
i=i+1
</code><... | 0 | 2014-07-22T00:03:36Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 32,330,757 | <p>Whilst playing with prime numbers in Python V3 I noticed that the smallest number by which a composite(non-prime) number is divisible is itself always a prime that is less than the square root of the number under test.</p>
<p>Below is my implementation of that finding to calculate the first N prime numbers.</p>
<p... | 0 | 2015-09-01T11:45:13Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 33,512,948 | <p>This is my version</p>
<pre><code>import timeit
import math
__author__ = 'rain'
primes = [2]
def is_prime(n):
for prime in primes:
if n % prime == 0:
return False
return True
def find_nth_prime(n):
current_index = 0
while(len(primes) < n):
if current_index == 0:
... | 0 | 2015-11-04T02:55:46Z | [
"python",
"primes"
] |
To find first N prime numbers in python | 1,628,949 | <p>I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
... | 8 | 2009-10-27T05:44:35Z | 35,576,949 | <p>Try this:</p>
<pre><code>primeList = []
for num in range(2,10000):
if all(num%i!=0 for i in range(2,num)):
primeList.append(num)
x = int(raw_input("Enter n: "))
for i in range(x):
print primeList[i]
</code></pre>
| 0 | 2016-02-23T11:55:18Z | [
"python",
"primes"
] |
Is it possible exclude test directories from coverage.py reports? | 1,628,996 | <p>I'm kind of a rookie with python unit testing, and particularly coverage.py. Is it desirable to have coverage reports include the coverage of your actual test files?</p>
<p>Here's a screenshot of my <a href="http://kylefox-awesome-stuff.s3.amazonaws.com/coverage.png">HTML report</a> as an example.</p>
<p>You can ... | 13 | 2009-10-27T06:08:06Z | 1,629,194 | <p>It's a good idea to see the coverage of your tests as it can point to problems. If your test code isn't being run then there wasn't much point in writing it!</p>
<p>The one I always get is when I give two unit test functions the same name - I add a new test several months after the original and just happen to pick ... | 14 | 2009-10-27T07:19:37Z | [
"python",
"testing",
"software-quality",
"code-coverage",
"coverage.py"
] |
Is it possible exclude test directories from coverage.py reports? | 1,628,996 | <p>I'm kind of a rookie with python unit testing, and particularly coverage.py. Is it desirable to have coverage reports include the coverage of your actual test files?</p>
<p>Here's a screenshot of my <a href="http://kylefox-awesome-stuff.s3.amazonaws.com/coverage.png">HTML report</a> as an example.</p>
<p>You can ... | 13 | 2009-10-27T06:08:06Z | 20,738,918 | <p><code>coverage html --omit="*/test*" -d tests/coverage</code></p>
| 12 | 2013-12-23T07:30:08Z | [
"python",
"testing",
"software-quality",
"code-coverage",
"coverage.py"
] |
python: sth like parametrized inheritance | 1,629,597 | <p>I want my classes <code>X</code> and <code>Y</code> to have a method <code>f(x)</code> which calls a function <code>func(x, y)</code> so that <code>X.f(x)</code> always calls <code>func(x, 1)</code> and <code>Y.f(x)</code> always calls <code>func(x, 2)</code></p>
<pre><code>class X(object):
def f(self, x):
... | 1 | 2009-10-27T09:16:43Z | 1,629,639 | <p>Python is more flexible than you give it credit.</p>
<p>I think you want something like this:</p>
<pre><code>class B(object):
def f(self,x):
func(x, self.param)
class X(B):
param=1
class Y(B):
param=2
</code></pre>
<p><strong>NB</strong> </p>
<ul>
<li>note the method f has self as the
firs... | 6 | 2009-10-27T09:28:19Z | [
"python",
"inheritance"
] |
python: sth like parametrized inheritance | 1,629,597 | <p>I want my classes <code>X</code> and <code>Y</code> to have a method <code>f(x)</code> which calls a function <code>func(x, y)</code> so that <code>X.f(x)</code> always calls <code>func(x, 1)</code> and <code>Y.f(x)</code> always calls <code>func(x, 2)</code></p>
<pre><code>class X(object):
def f(self, x):
... | 1 | 2009-10-27T09:16:43Z | 1,629,783 | <p>You could use a class decorator (Python 2.6 and up) if you just want to add a common function to several classes (instead of using inheritance).</p>
<pre><code>def addF(y):
def f(self, x):
return "Hello", x, "and", y
def decorate(cls):
cls.f = f
return cls
return decorate
@ad... | 1 | 2009-10-27T10:04:19Z | [
"python",
"inheritance"
] |
python script to match C function signature in multiple lines | 1,629,611 | <p>I am reading .c file to look out for functions defined in it and count number of lines in each function.
My problem is that I am unable to look for function name/signature spanned across multiple ines.
I have the list of function names of .c file and i am matching the function names of this list with functions in ... | 0 | 2009-10-27T09:20:13Z | 1,629,645 | <p>I suggest you write a simple parser for the C language.</p>
<p>One of the examples in the <a href="http://www.pragprog.com/titles/tpantlr/the-definitive-antlr-reference" rel="nofollow">ANTLR book</a> does something similar to what you're after.</p>
<p><a href="http://pyparsing.wikispaces.com" rel="nofollow">Pypars... | 1 | 2009-10-27T09:29:28Z | [
"python"
] |
python script to match C function signature in multiple lines | 1,629,611 | <p>I am reading .c file to look out for functions defined in it and count number of lines in each function.
My problem is that I am unable to look for function name/signature spanned across multiple ines.
I have the list of function names of .c file and i am matching the function names of this list with functions in ... | 0 | 2009-10-27T09:20:13Z | 1,629,653 | <p>If you have definition that matches "exactly" then you can use regex:</p>
<pre><code>int\s+main\s*\(\s*void\s*\)\s*;
</code></pre>
<p>where \s* means zero or more whitechars, and \s+ one or more whitechars.</p>
<p>To use it with multiline search you can define it like:</p>
<pre><code>RE_MAIN = re.compile(r'int\s... | 0 | 2009-10-27T09:32:28Z | [
"python"
] |
Alter XML while preserving layout | 1,629,687 | <p>What would you use to alter an XML-file while preserving as much as possible of layout, including indentation and comments?</p>
<p>My problem is that I have a couple of massive hand-edited XML-files describing a user interface, and now I need to translate several attributes to another language.</p>
<p>I've tried d... | 4 | 2009-10-27T09:40:25Z | 1,629,709 | <p>If you use an XSLT processor such as <a href="http://www.blnz.com/xt/index.html" rel="nofollow">xt</a>, then you can write extension methods in Java that can perform any arbitrary transformation you need.</p>
<p>Having said that, I have used Python's <a href="http://docs.python.org/library/xml.dom.minidom.html" rel... | 1 | 2009-10-27T09:44:58Z | [
"python",
"xml",
"elementtree"
] |
Alter XML while preserving layout | 1,629,687 | <p>What would you use to alter an XML-file while preserving as much as possible of layout, including indentation and comments?</p>
<p>My problem is that I have a couple of massive hand-edited XML-files describing a user interface, and now I need to translate several attributes to another language.</p>
<p>I've tried d... | 4 | 2009-10-27T09:40:25Z | 1,630,614 | <p>Any DOM manipulation module should suite your needs. Layout is just a text data, so it's represented as text nodes in DOM:</p>
<pre><code>>>> from xml.dom.minidom import parseString
>>> dom = parseString('''\
... <message>
... <text>
... Hello!
... </text>
... </messag... | 2 | 2009-10-27T12:56:01Z | [
"python",
"xml",
"elementtree"
] |
locale.getlocale() problems on OSX | 1,629,699 | <p>I need to get the system locale to do a number of things, ultimately I want to translate my app using gettext. I am going to distribute it on both Linux and OSX, but I ran into problems on OSX Snow Leopard:</p>
<pre><code>$ python
Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26)
[GCC 4.3.2] on linux2
Type "help", ... | 1 | 2009-10-27T09:42:31Z | 1,629,919 | <p>Odd on OSX (Smow Leopard 10.6.1) I get</p>
<pre><code>$ python
Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getlocale()
(None, None)
>>>... | 3 | 2009-10-27T10:29:16Z | [
"python",
"osx",
"localization",
"osx-snow-leopard",
"locale"
] |
locale.getlocale() problems on OSX | 1,629,699 | <p>I need to get the system locale to do a number of things, ultimately I want to translate my app using gettext. I am going to distribute it on both Linux and OSX, but I ran into problems on OSX Snow Leopard:</p>
<pre><code>$ python
Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26)
[GCC 4.3.2] on linux2
Type "help", ... | 1 | 2009-10-27T09:42:31Z | 1,631,002 | <p>Looks like you can change locale by changing environment variable <code>LC_ALL</code>.</p>
<pre><code>$ export LC_ALL=C
$ python
Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ... | 3 | 2009-10-27T13:59:08Z | [
"python",
"osx",
"localization",
"osx-snow-leopard",
"locale"
] |
locale.getlocale() problems on OSX | 1,629,699 | <p>I need to get the system locale to do a number of things, ultimately I want to translate my app using gettext. I am going to distribute it on both Linux and OSX, but I ran into problems on OSX Snow Leopard:</p>
<pre><code>$ python
Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26)
[GCC 4.3.2] on linux2
Type "help", ... | 1 | 2009-10-27T09:42:31Z | 8,819,223 | <p>Addmittedly a horrible hack, but I inserted this:</p>
<pre><code>import platform
# ...
# XXX horrendous OS X invalid locale hack
if platform.system() == 'Darwin':
import locale
if locale.getlocale()[0] is None:
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
</code></pre>
<p>at an early point in a... | 2 | 2012-01-11T12:27:27Z | [
"python",
"osx",
"localization",
"osx-snow-leopard",
"locale"
] |
locale.getlocale() problems on OSX | 1,629,699 | <p>I need to get the system locale to do a number of things, ultimately I want to translate my app using gettext. I am going to distribute it on both Linux and OSX, but I ran into problems on OSX Snow Leopard:</p>
<pre><code>$ python
Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26)
[GCC 4.3.2] on linux2
Type "help", ... | 1 | 2009-10-27T09:42:31Z | 17,966,818 | <p>From <a href="http://stackoverflow.com/a/8161863/125617">here</a>: Try adding or editing the <code>~/.profile</code> or <code>~/.bash_profile</code> file for it to correctly export your locale settings upon initiating a new session.</p>
<pre><code>export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
</code></pre>
| 1 | 2013-07-31T09:38:18Z | [
"python",
"osx",
"localization",
"osx-snow-leopard",
"locale"
] |
locale.getlocale() problems on OSX | 1,629,699 | <p>I need to get the system locale to do a number of things, ultimately I want to translate my app using gettext. I am going to distribute it on both Linux and OSX, but I ran into problems on OSX Snow Leopard:</p>
<pre><code>$ python
Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26)
[GCC 4.3.2] on linux2
Type "help", ... | 1 | 2009-10-27T09:42:31Z | 35,722,992 | <p>Old question, but this may help others: this is a Python bug that as of March 2016 is still unresolved in either Python 2 or 3: <a href="https://bugs.python.org/issue18378" rel="nofollow">https://bugs.python.org/issue18378</a> .</p>
<p>The summary is that Python assumes GNU-like locales and balks on (POSIXly correc... | 0 | 2016-03-01T12:29:34Z | [
"python",
"osx",
"localization",
"osx-snow-leopard",
"locale"
] |
How to find length of an element in a list? | 1,629,728 | <p>I'm just starting with programming. I have a list of a few strings and now I need to print the biggest (in length) one.
So I first want to just print the lengths of elements. I was trying things like this:</p>
<pre><code>l = ("xxxxxxxxx", "yyyy","zz")
for i in range(len(l):
</code></pre>
<p>So how do I do it?</p>... | 2 | 2009-10-27T09:50:33Z | 1,629,744 | <p>To print the lengths of the elements:</p>
<pre><code>elements = ["xxxxxx", "yyy", "z"]
for element in elements:
print len(element)
</code></pre>
<p>I recommend you read some tutorial material, for instance <a href="http://docs.python.org/tutorial/" rel="nofollow">http://docs.python.org/tutorial/</a></p>
| 3 | 2009-10-27T09:54:32Z | [
"python",
"list"
] |
How to find length of an element in a list? | 1,629,728 | <p>I'm just starting with programming. I have a list of a few strings and now I need to print the biggest (in length) one.
So I first want to just print the lengths of elements. I was trying things like this:</p>
<pre><code>l = ("xxxxxxxxx", "yyyy","zz")
for i in range(len(l):
</code></pre>
<p>So how do I do it?</p>... | 2 | 2009-10-27T09:50:33Z | 1,629,756 | <p>The following code will print the largest string in the set:</p>
<pre><code>l = ["abcdev", "xx","abcedeerer"]
len_0 = len(l[0])
pos = 0
for i in range(0,len(l)):
if len(l[i]) > len_0:
pos = i
print l[pos]
</code></pre>
| 1 | 2009-10-27T09:57:51Z | [
"python",
"list"
] |
How to find length of an element in a list? | 1,629,728 | <p>I'm just starting with programming. I have a list of a few strings and now I need to print the biggest (in length) one.
So I first want to just print the lengths of elements. I was trying things like this:</p>
<pre><code>l = ("xxxxxxxxx", "yyyy","zz")
for i in range(len(l):
</code></pre>
<p>So how do I do it?</p>... | 2 | 2009-10-27T09:50:33Z | 1,629,774 | <p>just ask for the max according to the length</p>
<p><code>print max(["qsf","qsqsdqsd","qs"], key = len)</code></p>
| 2 | 2009-10-27T10:01:56Z | [
"python",
"list"
] |
How to find length of an element in a list? | 1,629,728 | <p>I'm just starting with programming. I have a list of a few strings and now I need to print the biggest (in length) one.
So I first want to just print the lengths of elements. I was trying things like this:</p>
<pre><code>l = ("xxxxxxxxx", "yyyy","zz")
for i in range(len(l):
</code></pre>
<p>So how do I do it?</p>... | 2 | 2009-10-27T09:50:33Z | 1,629,777 | <pre><code>l = ("xxxxxxxxx", "yyyy","zz")
print(max(l, key=len))
</code></pre>
<p>First of all you don't have a list, you have a tuple. this code will work for any sequence, however; both lists and tuples are sequences (as well as strings, sets, etc). So, the <code>max</code> function takes a <code>key</code> argument... | 14 | 2009-10-27T10:02:29Z | [
"python",
"list"
] |
How to find length of an element in a list? | 1,629,728 | <p>I'm just starting with programming. I have a list of a few strings and now I need to print the biggest (in length) one.
So I first want to just print the lengths of elements. I was trying things like this:</p>
<pre><code>l = ("xxxxxxxxx", "yyyy","zz")
for i in range(len(l):
</code></pre>
<p>So how do I do it?</p>... | 2 | 2009-10-27T09:50:33Z | 1,629,786 | <pre><code>>>> sorted(['longest','long','longer'],key=len)[-1]
'longest'
</code></pre>
<p>UPDATE: SilentGhost's solution is a lot nicer.</p>
| 2 | 2009-10-27T10:05:04Z | [
"python",
"list"
] |
How to find length of an element in a list? | 1,629,728 | <p>I'm just starting with programming. I have a list of a few strings and now I need to print the biggest (in length) one.
So I first want to just print the lengths of elements. I was trying things like this:</p>
<pre><code>l = ("xxxxxxxxx", "yyyy","zz")
for i in range(len(l):
</code></pre>
<p>So how do I do it?</p>... | 2 | 2009-10-27T09:50:33Z | 29,841,919 | <p>This code maps "len" function over the list, to get another list containing the length of every item.</p>
<pre><code>mylist = ("xxxxxxxxx", "yyyy","zz")
len_mylist = map(len, mylist)
max_position = len_mylist.index(max(len_mylist))
my_item = mylist[max_position]
print('The largest item of my list is: ' + my_item)
p... | 0 | 2015-04-24T08:03:52Z | [
"python",
"list"
] |
Python string formatting special characters | 1,629,755 | <p>How do you make the following code work?</p>
<pre><code>example = "%%(test)%" % {'test':'name',}
print example
</code></pre>
<p>Where the desired output is "%name%"</p>
<p>Thanks</p>
| 3 | 2009-10-27T09:57:44Z | 1,629,766 | <pre><code>example = "%%%(test)s%%" % {'test':'name',}
print example
</code></pre>
<p><code>%(key)s</code> is a placeholder for a string identified by <code>key</code>. <code>%%</code> escapes <code>%</code> when using the <code>%</code> operator.</p>
| 5 | 2009-10-27T10:00:27Z | [
"python",
"string-formatting"
] |
Python string formatting special characters | 1,629,755 | <p>How do you make the following code work?</p>
<pre><code>example = "%%(test)%" % {'test':'name',}
print example
</code></pre>
<p>Where the desired output is "%name%"</p>
<p>Thanks</p>
| 3 | 2009-10-27T09:57:44Z | 1,629,861 | <p>An alternative is to use the new <a href="http://www.python.org/dev/peps/pep-3101/">Advanced String Formatting</a></p>
<pre><code>>>> example = "%{test}%".format(test="name")
>>> print example
%name%
</code></pre>
| 7 | 2009-10-27T10:19:23Z | [
"python",
"string-formatting"
] |
Are there any known issues with django and multithreading? | 1,629,800 | <p>I need to develop an app that runs side by side with a django-app.
This will be the first time i develop a multithreaded app that runs next to a django-app so are there any 'gotchas' and 'traps' i should be aware of?</p>
| 1 | 2009-10-27T10:08:39Z | 1,629,875 | <p>What do you mean side by side with a django-app? Could you please elaborate a bit on what you are you planning to achieve? Then helping out/answering should be easier.</p>
<p><hr /></p>
<h2>Answer on OP's 1st edit</h2>
<p><hr /></p>
<p>Ah. Okey. I have encountered such an application which does exactly the thing... | 0 | 2009-10-27T10:20:34Z | [
"python",
"django",
"multithreading"
] |
Are there any known issues with django and multithreading? | 1,629,800 | <p>I need to develop an app that runs side by side with a django-app.
This will be the first time i develop a multithreaded app that runs next to a django-app so are there any 'gotchas' and 'traps' i should be aware of?</p>
| 1 | 2009-10-27T10:08:39Z | 1,629,913 | <p>Generally, your Django app already is multi-threaded. That's the way most of the standard Django servers operate -- they can tolerate multiple WSGI threads sending requests to them.</p>
<p>Further, you'll almost always have Django running under Apache, which is also multi-threaded.</p>
<p>If you use <code>mod_wsg... | 2 | 2009-10-27T10:27:37Z | [
"python",
"django",
"multithreading"
] |
Are there any known issues with django and multithreading? | 1,629,800 | <p>I need to develop an app that runs side by side with a django-app.
This will be the first time i develop a multithreaded app that runs next to a django-app so are there any 'gotchas' and 'traps' i should be aware of?</p>
| 1 | 2009-10-27T10:08:39Z | 1,629,943 | <p>If you want to expose your django-app to some external software, you need to create an API for your application.</p>
<p>You should look at REST <a href="http://code.google.com/p/django-rest-interface/" rel="nofollow">http://code.google.com/p/django-rest-interface/</a> and XMLRPC <a href="http://code.google.com/p/dj... | 0 | 2009-10-27T10:33:46Z | [
"python",
"django",
"multithreading"
] |
Chaining Deferred Tasks with Google App Engine | 1,630,001 | <p>I have a website I am looking to stay updated with and scrape some content from there every day. I know the site is updated manually at a certain time, and I've set cron schedules to reflect this, but since it is updated manually it could be 10 or even 20 minutes later.</p>
<p>Right now I have a hack-ish cron updat... | 0 | 2009-10-27T10:44:45Z | 1,636,387 | <p>The example you give should work just fine. You need to add logging to determine if deferred.defer is being called when you think it is. More information would help, too: How is siteHasNotBeenUpdated set?</p>
| 2 | 2009-10-28T10:28:37Z | [
"python",
"google-app-engine",
"deferred-execution"
] |
What is the pythonic way to detect the last element in a python 'for' loop? | 1,630,320 | <p>I'd like to know the best way (more compact and "pythonic" way) to do a special treatment for the last element in a for loop. There is a piece of code that should be called only <em>between</em> elements, being suppressed in the last one.</p>
<p>Here is how I currently do it:</p>
<pre><code>for i, data in enumerat... | 69 | 2009-10-27T11:54:33Z | 1,630,350 | <p>Most of the times it is easier (and cheaper) to make the <em>first</em> iteration the special case instead of the last one:</p>
<pre><code>first = True
for data in data_list:
if first:
first = False
else:
between_items()
item()
</code></pre>
<p>This will work for any iterable, even for... | 65 | 2009-10-27T12:02:28Z | [
"for-loop",
"python",
"idioms",
"fencepost"
] |
What is the pythonic way to detect the last element in a python 'for' loop? | 1,630,320 | <p>I'd like to know the best way (more compact and "pythonic" way) to do a special treatment for the last element in a for loop. There is a piece of code that should be called only <em>between</em> elements, being suppressed in the last one.</p>
<p>Here is how I currently do it:</p>
<pre><code>for i, data in enumerat... | 69 | 2009-10-27T11:54:33Z | 1,630,359 | <p>If you're simply looking to modify the last element in <code>data_list</code> then you can simply use the notation:</p>
<pre><code>L[-1]
</code></pre>
<p>However, it looks like you're doing more than that. There is nothing really wrong with your way. I even took a quick glance at some <a href="http://code.djangopr... | 11 | 2009-10-27T12:05:19Z | [
"for-loop",
"python",
"idioms",
"fencepost"
] |
What is the pythonic way to detect the last element in a python 'for' loop? | 1,630,320 | <p>I'd like to know the best way (more compact and "pythonic" way) to do a special treatment for the last element in a for loop. There is a piece of code that should be called only <em>between</em> elements, being suppressed in the last one.</p>
<p>Here is how I currently do it:</p>
<pre><code>for i, data in enumerat... | 69 | 2009-10-27T11:54:33Z | 1,630,396 | <p>Is there no possibility to iterate over all-but the last element, and treat the last one outside of the loop? After all, a loop is created to do something similar to all elements you loop over; if one element needs something special, it shouldn't be in the loop.</p>
<p>(see also this question: <a href="http://stac... | 3 | 2009-10-27T12:11:17Z | [
"for-loop",
"python",
"idioms",
"fencepost"
] |
What is the pythonic way to detect the last element in a python 'for' loop? | 1,630,320 | <p>I'd like to know the best way (more compact and "pythonic" way) to do a special treatment for the last element in a for loop. There is a piece of code that should be called only <em>between</em> elements, being suppressed in the last one.</p>
<p>Here is how I currently do it:</p>
<pre><code>for i, data in enumerat... | 69 | 2009-10-27T11:54:33Z | 1,630,410 | <p>There is nothing wrong with your way, unless you will have 100 000 loops and wants save 100 000 "if" statements. In that case, you can go that way :</p>
<pre><code>iterable = [1,2,3] # Your date
iterator = iter(iterable) # get the data iterator
try : # wrap all in a try / except
while 1 :
item = ite... | 2 | 2009-10-27T12:15:19Z | [
"for-loop",
"python",
"idioms",
"fencepost"
] |
What is the pythonic way to detect the last element in a python 'for' loop? | 1,630,320 | <p>I'd like to know the best way (more compact and "pythonic" way) to do a special treatment for the last element in a for loop. There is a piece of code that should be called only <em>between</em> elements, being suppressed in the last one.</p>
<p>Here is how I currently do it:</p>
<pre><code>for i, data in enumerat... | 69 | 2009-10-27T11:54:33Z | 1,630,742 | <p>You can use a sliding window over the input data to get a peek at the next value and use a sentinel to detect the last value. This works on any iterable, so you don't need to know the length beforehand. The pairwise implementation is from <a href="http://docs.python.org/library/itertools.html" rel="nofollow">itertoo... | 3 | 2009-10-27T13:17:21Z | [
"for-loop",
"python",
"idioms",
"fencepost"
] |
What is the pythonic way to detect the last element in a python 'for' loop? | 1,630,320 | <p>I'd like to know the best way (more compact and "pythonic" way) to do a special treatment for the last element in a for loop. There is a piece of code that should be called only <em>between</em> elements, being suppressed in the last one.</p>
<p>Here is how I currently do it:</p>
<pre><code>for i, data in enumerat... | 69 | 2009-10-27T11:54:33Z | 1,630,853 | <p>The 'code between' is an example of the <strong>Head-Tail</strong> pattern.</p>
<p>You have an item, which is followed by a sequence of ( between, item ) pairs. You can also view this as a sequence of (item, between) pairs followed by an item. It's generally simpler to take the first element as special and all th... | 13 | 2009-10-27T13:38:36Z | [
"for-loop",
"python",
"idioms",
"fencepost"
] |
What is the pythonic way to detect the last element in a python 'for' loop? | 1,630,320 | <p>I'd like to know the best way (more compact and "pythonic" way) to do a special treatment for the last element in a for loop. There is a piece of code that should be called only <em>between</em> elements, being suppressed in the last one.</p>
<p>Here is how I currently do it:</p>
<pre><code>for i, data in enumerat... | 69 | 2009-10-27T11:54:33Z | 1,630,865 | <p>Assuming input as an iterator, here's a way using tee and izip from itertools:</p>
<pre><code>from itertools import tee, izip
items, between = tee(input_iterator, 2) # Input must be an iterator.
first = items.next()
do_to_every_item(first) # All "do to every" operations done to first item go here.
for i, b in izi... | 1 | 2009-10-27T13:39:40Z | [
"for-loop",
"python",
"idioms",
"fencepost"
] |
What is the pythonic way to detect the last element in a python 'for' loop? | 1,630,320 | <p>I'd like to know the best way (more compact and "pythonic" way) to do a special treatment for the last element in a for loop. There is a piece of code that should be called only <em>between</em> elements, being suppressed in the last one.</p>
<p>Here is how I currently do it:</p>
<pre><code>for i, data in enumerat... | 69 | 2009-10-27T11:54:33Z | 1,633,483 | <p>This is similar to Ants Aasma's approach but without using the itertools module. It's also a lagging iterator which looks-ahead a single element in the iterator stream:</p>
<pre><code>def last_iter(it):
# Ensure it's an iterator and get the first field
it = iter(it)
prev = next(it)
for item in it:
... | 8 | 2009-10-27T20:32:51Z | [
"for-loop",
"python",
"idioms",
"fencepost"
] |
What is the pythonic way to detect the last element in a python 'for' loop? | 1,630,320 | <p>I'd like to know the best way (more compact and "pythonic" way) to do a special treatment for the last element in a for loop. There is a piece of code that should be called only <em>between</em> elements, being suppressed in the last one.</p>
<p>Here is how I currently do it:</p>
<pre><code>for i, data in enumerat... | 69 | 2009-10-27T11:54:33Z | 30,885,340 | <p>Although that question is pretty old, I came here via google and I found a quite simple way: List slicing. Let's say you want to put an '&' between all list entries.</p>
<pre><code>s = ""
l = [1, 2, 3]
for i in l[:-1]:
s = s + str(i) + ' & '
s = s + str(l[-1])
</code></pre>
<p>This returns '1 & 2 &... | 5 | 2015-06-17T07:46:09Z | [
"for-loop",
"python",
"idioms",
"fencepost"
] |
What is the pythonic way to detect the last element in a python 'for' loop? | 1,630,320 | <p>I'd like to know the best way (more compact and "pythonic" way) to do a special treatment for the last element in a for loop. There is a piece of code that should be called only <em>between</em> elements, being suppressed in the last one.</p>
<p>Here is how I currently do it:</p>
<pre><code>for i, data in enumerat... | 69 | 2009-10-27T11:54:33Z | 30,993,336 | <p>Use slicing and <code>is</code> to check for the last element:</p>
<pre><code>for data in data_list:
<code_that_is_done_for_every_element>
if not data is data_list[-1]:
<code_that_is_done_between_elements>
</code></pre>
<p><strong>Caveat emptor</strong>: This only works if all elements ... | 3 | 2015-06-23T03:27:22Z | [
"for-loop",
"python",
"idioms",
"fencepost"
] |
What is the pythonic way to detect the last element in a python 'for' loop? | 1,630,320 | <p>I'd like to know the best way (more compact and "pythonic" way) to do a special treatment for the last element in a for loop. There is a piece of code that should be called only <em>between</em> elements, being suppressed in the last one.</p>
<p>Here is how I currently do it:</p>
<pre><code>for i, data in enumerat... | 69 | 2009-10-27T11:54:33Z | 34,686,726 | <p>if you are going through the list, for me this worked too:</p>
<pre><code>for j in range(0, len(Array)):
if len(Array) - j > 1:
notLast()
</code></pre>
| 1 | 2016-01-08T21:51:37Z | [
"for-loop",
"python",
"idioms",
"fencepost"
] |
What is the pythonic way to detect the last element in a python 'for' loop? | 1,630,320 | <p>I'd like to know the best way (more compact and "pythonic" way) to do a special treatment for the last element in a for loop. There is a piece of code that should be called only <em>between</em> elements, being suppressed in the last one.</p>
<p>Here is how I currently do it:</p>
<pre><code>for i, data in enumerat... | 69 | 2009-10-27T11:54:33Z | 38,376,487 | <p>Google brought me to this old question and I think I could add a different approach to this problem.</p>
<p>Most of the answers here would deal with a proper treatment of a for loop control as it was asked, but if the data_list is destructible, I would suggest that you pop the items from the list until you end up ... | 1 | 2016-07-14T14:09:10Z | [
"for-loop",
"python",
"idioms",
"fencepost"
] |
Django Zip upload permission problem | 1,630,427 | <p>I have few uploads in this app, uploading csv files is working fine.</p>
<p>I have a model that has zip upload in it. Zip file is uploaded, can be viewed, but having issues extracting it.</p>
<pre>
class Message(models.Model):
uploadFile = models.FileField(_('images file (.zip)'),
... | 0 | 2009-10-27T12:19:46Z | 1,630,691 | <p>It's not really an issue with the zip file, it's probably an issue with your directory's permissions.</p>
<p>Take a look at the permissions for /backend/media/new. Is <code>new</code> a folder being created by the zip or is that where you're trying to unzip too? Make sure the groups for the folders also match.</p>
... | 1 | 2009-10-27T13:09:25Z | [
"python",
"django",
"zip"
] |
Django Zip upload permission problem | 1,630,427 | <p>I have few uploads in this app, uploading csv files is working fine.</p>
<p>I have a model that has zip upload in it. Zip file is uploaded, can be viewed, but having issues extracting it.</p>
<pre>
class Message(models.Model):
uploadFile = models.FileField(_('images file (.zip)'),
... | 0 | 2009-10-27T12:19:46Z | 1,631,366 | <p>it works with ZipFile.extractall </p>
| 0 | 2009-10-27T14:53:34Z | [
"python",
"django",
"zip"
] |
Best practice in python for return value on error vs. success | 1,630,706 | <p>In <strong>general</strong>, let's say you have a method like the below. </p>
<pre><code>def intersect_two_lists(self, list1, list2):
if not list1:
self.trap_error("union_two_lists: list1 must not be empty.")
return False
if not list2:
self.trap_error("union_two_lists: list2 must not... | 27 | 2009-10-27T13:11:15Z | 1,630,722 | <p>I like to return a tuple:</p>
<blockquote>
<p>(True, some_result)</p>
<p>(False, some_useful_response)</p>
</blockquote>
<p>The *some_useful_response* object can be used for handling the return condition or can serve to display debugging info.</p>
<p><strong>NOTE</strong>: this technique applies for <stron... | 6 | 2009-10-27T13:14:29Z | [
"python",
"return"
] |
Best practice in python for return value on error vs. success | 1,630,706 | <p>In <strong>general</strong>, let's say you have a method like the below. </p>
<pre><code>def intersect_two_lists(self, list1, list2):
if not list1:
self.trap_error("union_two_lists: list1 must not be empty.")
return False
if not list2:
self.trap_error("union_two_lists: list2 must not... | 27 | 2009-10-27T13:11:15Z | 1,630,737 | <p>It'd be better to <a href="http://en.wikibooks.org/wiki/Python%5FProgramming/Exceptions">raise an exception</a> than return a special value. This is exactly what exceptions were designed for, to replace error codes with a more robust and structured error-handling mechanism.</p>
<pre><code>class IntersectException(E... | 16 | 2009-10-27T13:17:10Z | [
"python",
"return"
] |
Best practice in python for return value on error vs. success | 1,630,706 | <p>In <strong>general</strong>, let's say you have a method like the below. </p>
<pre><code>def intersect_two_lists(self, list1, list2):
if not list1:
self.trap_error("union_two_lists: list1 must not be empty.")
return False
if not list2:
self.trap_error("union_two_lists: list2 must not... | 27 | 2009-10-27T13:11:15Z | 1,630,760 | <p>First, whatever you do don't return a result and an error message. That's a really bad way to handle errors and will cause you endless headaches. <strong>If you need to indicate an error always raise an exception</strong>.</p>
<p>I usually tend to avoid raising errors unless it is necessary. In your example throwin... | 38 | 2009-10-27T13:20:40Z | [
"python",
"return"
] |
Best practice in python for return value on error vs. success | 1,630,706 | <p>In <strong>general</strong>, let's say you have a method like the below. </p>
<pre><code>def intersect_two_lists(self, list1, list2):
if not list1:
self.trap_error("union_two_lists: list1 must not be empty.")
return False
if not list2:
self.trap_error("union_two_lists: list2 must not... | 27 | 2009-10-27T13:11:15Z | 1,631,148 | <p>Exceptions are definitely better (and more Pythonic) than status returns. For much more on this: <a href="http://nedbatchelder.com/text/exceptions-vs-status.html">Exceptions vs. status returns</a></p>
| 11 | 2009-10-27T14:19:50Z | [
"python",
"return"
] |
Best practice in python for return value on error vs. success | 1,630,706 | <p>In <strong>general</strong>, let's say you have a method like the below. </p>
<pre><code>def intersect_two_lists(self, list1, list2):
if not list1:
self.trap_error("union_two_lists: list1 must not be empty.")
return False
if not list2:
self.trap_error("union_two_lists: list2 must not... | 27 | 2009-10-27T13:11:15Z | 1,631,407 | <p>The general case is to throw exceptions for exceptional circumstances. I wish that I could remember the exact quote (or who said it), but you should strive for functions that accept as many values and types as is reasonable and maintain a very narrowly defined behavior. This is a variant of what <a href="http://st... | 1 | 2009-10-27T15:01:05Z | [
"python",
"return"
] |
No IDLE for Python 3? | 1,630,728 | <p>I installed Python 3.1 yesterday on my Windows Vista PC, and was surprised to find that the version of IDLE is 2.6.4, for "Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32"</p>
<p>I was hoping to use IDLE to investigate some of the new features of Python 3...</p>
<p>I guess I'm... | 5 | 2009-10-27T13:15:19Z | 1,630,899 | <p>Got it! I changed the Target of the shortcut to "c:\Python31\pythonw.exe" "c:\Python31\Lib\idlelib\idle.pyW" (with the quotes), and now the shortcut (and shortcut key) open version 3.1.1 of IDLE. Idea was from the 1st answer to the question at <a href="http://stackoverflow.com/questions/118260/how-to-start-idle-... | 4 | 2009-10-27T13:45:07Z | [
"python",
"python-3.x",
"python-idle"
] |
No IDLE for Python 3? | 1,630,728 | <p>I installed Python 3.1 yesterday on my Windows Vista PC, and was surprised to find that the version of IDLE is 2.6.4, for "Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32"</p>
<p>I was hoping to use IDLE to investigate some of the new features of Python 3...</p>
<p>I guess I'm... | 5 | 2009-10-27T13:15:19Z | 19,543,322 | <p>Type 'idle3' in the terminal window. That should launch your copy of idle 3.1</p>
| -1 | 2013-10-23T13:40:30Z | [
"python",
"python-3.x",
"python-idle"
] |
In django, how to write a query that selects all possible combinations of four integers? | 1,631,333 | <p>I'm writing a Game Website, where the draw is a series of four digits. e.g 1234</p>
<p>I"m trying to write a query in django that will select all winners based on the four digits entered. winners are any combination of the same numbers or the same combination, 1 2 3 4, 2 3 1 4, 4 1 3 2 are all winners.</p>
<p>how... | 1 | 2009-10-27T14:48:32Z | 1,631,545 | <p>Code:</p>
<pre><code>from itertools import permutations
winning_numbers = "1234"
winning_combinations = map(lambda v: "".join(v), list(permutations(winning_numbers, 4)))
winners = GamesPlayed.objects.filter(numbers__in=winning_combinations)
</code></pre>
<p>Assuming GamesPlayed is the model object for all games p... | 0 | 2009-10-27T15:20:11Z | [
"python",
"django",
"django-models"
] |
In django, how to write a query that selects all possible combinations of four integers? | 1,631,333 | <p>I'm writing a Game Website, where the draw is a series of four digits. e.g 1234</p>
<p>I"m trying to write a query in django that will select all winners based on the four digits entered. winners are any combination of the same numbers or the same combination, 1 2 3 4, 2 3 1 4, 4 1 3 2 are all winners.</p>
<p>how... | 1 | 2009-10-27T14:48:32Z | 1,631,874 | <p>I'd advise adjusting the code to save the digits so that they are saved in sorted order. E.g. if the user puts in "5262" then it should store that as "2256". Then, when you select a winning set of digits, you can sort those, and filter by simple equality. This will perform much, much better than trying to check f... | 5 | 2009-10-27T16:05:25Z | [
"python",
"django",
"django-models"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.