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
Structured programming and Python generators?
1,745,333
<p><strong>Update:</strong> What I really wanted all along were <a href="http://pypi.python.org/pypi/greenlet" rel="nofollow">greenlets</a>.</p> <hr> <p><strong>Note:</strong> This question mutated a bit as people answered and forced me to "raise the stakes", as my trivial examples had trivial simplifications; rather...
6
2009-11-16T22:43:30Z
1,745,468
<p>Impractical (unfortunately) answer:</p> <pre><code>from __future__ import PEP0380 def sillyGenerator(): yield from quadraticRange(10) yield from quadraticRange(12) yield from quadraticRange(8) </code></pre> <p>Potentially practical reference: <a href="http://www.python.org/dev/peps/pep-0380/" rel="nof...
6
2009-11-16T23:10:58Z
[ "python", "generator" ]
Structured programming and Python generators?
1,745,333
<p><strong>Update:</strong> What I really wanted all along were <a href="http://pypi.python.org/pypi/greenlet" rel="nofollow">greenlets</a>.</p> <hr> <p><strong>Note:</strong> This question mutated a bit as people answered and forced me to "raise the stakes", as my trivial examples had trivial simplifications; rather...
6
2009-11-16T22:43:30Z
1,745,586
<blockquote> <p>However, I'd like to make my reusability criteria one notch harder: what if I need a control structure around my repeated generation?</p> </blockquote> <p><code>itertools</code> often helps even there - you need to provide concrete examples where you think it doesn't.</p> <blockquote> <p>For...
11
2009-11-16T23:34:58Z
[ "python", "generator" ]
Structured programming and Python generators?
1,745,333
<p><strong>Update:</strong> What I really wanted all along were <a href="http://pypi.python.org/pypi/greenlet" rel="nofollow">greenlets</a>.</p> <hr> <p><strong>Note:</strong> This question mutated a bit as people answered and forced me to "raise the stakes", as my trivial examples had trivial simplifications; rather...
6
2009-11-16T22:43:30Z
1,985,640
<p>There is a pattern which I call "generator kernel" where generators don't yield directly to the user but to some "kernel" loop that treats (some of) their yields as "system calls" with special meaning.</p> <p>You can apply it here by an intermediate function that accepts yielded generators and unrolls them automati...
1
2009-12-31T14:32:51Z
[ "python", "generator" ]
Structured programming and Python generators?
1,745,333
<p><strong>Update:</strong> What I really wanted all along were <a href="http://pypi.python.org/pypi/greenlet" rel="nofollow">greenlets</a>.</p> <hr> <p><strong>Note:</strong> This question mutated a bit as people answered and forced me to "raise the stakes", as my trivial examples had trivial simplifications; rather...
6
2009-11-16T22:43:30Z
4,583,247
<pre><code>class Communicator: def __init__(self, inflow): self.outflow = None self.inflow = inflow </code></pre> <p>Then you do:</p> <pre><code>c = Communicator(something) yield c response = c.outflow </code></pre> <p>And instead of the boilerplate code you can simply do:</p> <pre><code> for i ...
0
2011-01-03T09:11:37Z
[ "python", "generator" ]
How to allow a many-to-many relationship to be configured in Python
1,745,479
<p>I have a simple app which requires a many-to-many relationship to be configured as part of its set-up. For example, the app requires a list of repository URLs, a list of users and for each user, a subset of the repository URLs.</p> <p>I first thought of using a <code>config.py</code> file similar to the following:...
2
2009-11-16T23:13:29Z
1,745,580
<p>If you like the idea of representing structure by indentation (like in Python) then YAML will be perfect for you. If you don't want to rely on whitespace and prefer explicit syntax then better go with JSON. Both are easy to understand and popular, which means that there are Python libraries out there.</p> <p>Additi...
1
2009-11-16T23:34:30Z
[ "python", "configuration" ]
How to allow a many-to-many relationship to be configured in Python
1,745,479
<p>I have a simple app which requires a many-to-many relationship to be configured as part of its set-up. For example, the app requires a list of repository URLs, a list of users and for each user, a subset of the repository URLs.</p> <p>I first thought of using a <code>config.py</code> file similar to the following:...
2
2009-11-16T23:13:29Z
1,745,596
<p>The tactic I use is to put the whole application in a class, and then instead of having an importable config file, allow the user to pass in configuration to the constructor. Or, in more complicated cases they could even subclass the application class to add members or change behaviours. Although this does require a...
-1
2009-11-16T23:37:19Z
[ "python", "configuration" ]
How to allow a many-to-many relationship to be configured in Python
1,745,479
<p>I have a simple app which requires a many-to-many relationship to be configured as part of its set-up. For example, the app requires a list of repository URLs, a list of users and for each user, a subset of the repository URLs.</p> <p>I first thought of using a <code>config.py</code> file similar to the following:...
2
2009-11-16T23:13:29Z
1,745,809
<p>I would store the config in JSON format. For example:</p> <pre><code>cfg = """ { "repositories": { "repo1": "http://svn.example.com/repo1/", "repo2": "http://svn.example.com/repo2/", "repo3": "http://svn.example.com/repo3/" }, "user_repository_mapping": { "person_A": ["r...
2
2009-11-17T00:26:05Z
[ "python", "configuration" ]
What's the most Pythonic XHTML/HTML parser/generator/template module that supports DOM like access?
1,745,524
<p>It should be able to <strong>create</strong>, <strong>modify</strong> and <strong>read</strong> X/HTML in a highly <strong>object oriented</strong> way that still feels DOM like but is not obese, and is really <strong><em>Pythonic</em></strong>. Preferably it would deal with malformed HTML too, but we can skip this ...
7
2009-11-16T23:21:18Z
1,745,578
<p><a href="http://www.xml3k.org/Amara" rel="nofollow">Amara Bindery</a> provides the most Pythonic XML API I've seen. See the <a href="http://www.xml3k.org/Amara/QuickRef" rel="nofollow">quick reference</a>, <a href="http://www.xml3k.org/Amara/Manual" rel="nofollow">manual</a> and <a href="http://www.xml3k.org/Amara/...
1
2009-11-16T23:33:52Z
[ "python", "dom", "xhtml", "parsing", "template-engine" ]
What's the most Pythonic XHTML/HTML parser/generator/template module that supports DOM like access?
1,745,524
<p>It should be able to <strong>create</strong>, <strong>modify</strong> and <strong>read</strong> X/HTML in a highly <strong>object oriented</strong> way that still feels DOM like but is not obese, and is really <strong><em>Pythonic</em></strong>. Preferably it would deal with malformed HTML too, but we can skip this ...
7
2009-11-16T23:21:18Z
1,745,748
<p>The first part can for the most part be done by <a href="http://docs.python.org/library/xml.etree.elementtree.html" rel="nofollow">ElementTree</a>, but it takes a few more steps:</p> <pre><code>&gt;&gt;&gt; import xml.etree.ElementTree as ET &gt;&gt;&gt; html = ET.XML('&lt;html&gt;&lt;head&gt;&lt;title&gt;Hi&lt;/ti...
4
2009-11-17T00:13:10Z
[ "python", "dom", "xhtml", "parsing", "template-engine" ]
QtPython Qtreewidget Problem
1,745,661
<p>I trying to do a Qtreewidget to attend a customer design suggestion. I am coding it on QtPython. I did a first try using Qt Designer, then generated the code. But when I try to run it, an error comes out: </p> <pre><code>self.centralwidget.setSortingEnabled(__sortingEnabled) AttributeError: setSortingEnabled </code...
0
2009-11-16T23:51:04Z
1,745,785
<p>I'm assuming the code you posted is what you got when you ran your UI file through pyuic4. I found the PyQt UI compiler to be buggy sometimes. All you can do is fix the output manually and complain to the vendor.</p> <p>In your case, the line</p> <pre><code>self.centralwidget.setSortingEnabled(__sortingEnabled) </...
2
2009-11-17T00:21:01Z
[ "python", "qt", "qt4", "pyqt", "pyqt4" ]
QtPython Qtreewidget Problem
1,745,661
<p>I trying to do a Qtreewidget to attend a customer design suggestion. I am coding it on QtPython. I did a first try using Qt Designer, then generated the code. But when I try to run it, an error comes out: </p> <pre><code>self.centralwidget.setSortingEnabled(__sortingEnabled) AttributeError: setSortingEnabled </code...
0
2009-11-16T23:51:04Z
1,746,295
<p>Here is the solution:</p> <ol> <li>delete/comment only the following line: self.centralwidget.setSortingEnabled(__sortingEnabled)</li> </ol> <p>Then code:</p> <pre><code>def eqpt_centralwdg(self,MainWindow): self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") se...
0
2009-11-17T02:53:24Z
[ "python", "qt", "qt4", "pyqt", "pyqt4" ]
Validating Uploaded Files in Django
1,745,743
<p>A Django app that I am working has an <code>Event</code> model. An <code>Event</code> may have associated photos, static html files and pdf files.</p> <p>I would like to allow trusted users to upload these files, but I am wary about security, especially having read the following <a href="http://docs.djangoproject.c...
20
2009-11-17T00:12:02Z
1,745,840
<p>The first thing you want to do with the uploaded content is store it in a directory which is not directly accessible for downloading. If your app exists in <code>~/www/</code> consider putting your data in '~/data/`.</p> <p>The second thing, you need to determine what kind of file the user uploaded, and then creat...
6
2009-11-17T00:32:38Z
[ "python", "django", "security", "file-upload" ]
Validating Uploaded Files in Django
1,745,743
<p>A Django app that I am working has an <code>Event</code> model. An <code>Event</code> may have associated photos, static html files and pdf files.</p> <p>I would like to allow trusted users to upload these files, but I am wary about security, especially having read the following <a href="http://docs.djangoproject.c...
20
2009-11-17T00:12:02Z
1,750,810
<p>For images you might be able to just use <a href="http://www.pythonware.com/library/pil/handbook/introduction.htm">Python Imaging Library</a> (PIL).</p> <pre><code>Image.open(filepath) </code></pre> <p>If the file is not an image, an exception will be thrown. I'm pretty new to Python/Django so someone else might ...
14
2009-11-17T18:25:32Z
[ "python", "django", "security", "file-upload" ]
Validating Uploaded Files in Django
1,745,743
<p>A Django app that I am working has an <code>Event</code> model. An <code>Event</code> may have associated photos, static html files and pdf files.</p> <p>I would like to allow trusted users to upload these files, but I am wary about security, especially having read the following <a href="http://docs.djangoproject.c...
20
2009-11-17T00:12:02Z
1,789,938
<p>you can validate html files with <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a></p>
1
2009-11-24T13:03:05Z
[ "python", "django", "security", "file-upload" ]
Validating Uploaded Files in Django
1,745,743
<p>A Django app that I am working has an <code>Event</code> model. An <code>Event</code> may have associated photos, static html files and pdf files.</p> <p>I would like to allow trusted users to upload these files, but I am wary about security, especially having read the following <a href="http://docs.djangoproject.c...
20
2009-11-17T00:12:02Z
1,790,063
<p>'trusted users' is a subjective term. Is it people that you know in person or only someone who has created an account on your app? Don't give access to your filesystem to people that you don't know in person.</p> <p>Giving the ability to someone to upload a file is in any case a bit dangerous and I think that it sh...
2
2009-11-24T13:27:36Z
[ "python", "django", "security", "file-upload" ]
Validating Uploaded Files in Django
1,745,743
<p>A Django app that I am working has an <code>Event</code> model. An <code>Event</code> may have associated photos, static html files and pdf files.</p> <p>I would like to allow trusted users to upload these files, but I am wary about security, especially having read the following <a href="http://docs.djangoproject.c...
20
2009-11-17T00:12:02Z
1,790,921
<p>This is a little bit specific to your hosting environment, but here is what I do:</p> <p>Serve all user uploaded content with Nginx instead of apache, and serve it all as static content (it will not run any of the php or cgi, even if the users upload it)</p>
5
2009-11-24T15:46:46Z
[ "python", "django", "security", "file-upload" ]
Validating Uploaded Files in Django
1,745,743
<p>A Django app that I am working has an <code>Event</code> model. An <code>Event</code> may have associated photos, static html files and pdf files.</p> <p>I would like to allow trusted users to upload these files, but I am wary about security, especially having read the following <a href="http://docs.djangoproject.c...
20
2009-11-17T00:12:02Z
1,796,299
<p>All the answers are focusing on validating files. This is pretty much impossible.</p> <p>The Django devs aren't asking you to validate whether files can be executed <em>as</em> cgi files. They are just telling you not to put them in a place where they <em>will</em> be executed.</p> <p>You should put all Django stu...
15
2009-11-25T11:20:19Z
[ "python", "django", "security", "file-upload" ]
how can I filter on the second element in a tuple of tuples?
1,745,919
<p>In my model I have a field:</p> <pre><code> country = models.CharField(_('Country'), max_length=2, choices=COUNTRIES) </code></pre> <p>Where COUNTRIES is a tuple of tuples like this:</p> <pre><code>COUNTRIES = ( ('AF', _('Afghanistan')), </code></pre> <p>... and so on</p> <p>Now I want to filter an instan...
2
2009-11-17T00:49:17Z
1,745,952
<p>You cannot filter directly by the country name (the <code>choices</code> are only used in the UI, not in the database).</p> <p>If you get the full name as an input, lookup the code in the <code>COUNTRIES</code> tuple-of-tuples. For example:</p> <pre><code># ... initialize a lookup dictionary country_to_id_dict = d...
4
2009-11-17T00:58:31Z
[ "python", "django", "filter", "country" ]
Python tabstop-aware len() and padding functions
1,746,116
<p>Python's len() and padding functions like string.ljust() are not tabstop-aware, i.e. they treat '\t' like any other single-width character, and don't round len up to the nearest multiple of tabstop. Example: </p> <pre><code>len('Bear\tnecessities\t') </code></pre> <p>is 17 instead of 24 ( i.e. 4+(8-4)+11+(8-3) )</...
2
2009-11-17T01:54:07Z
1,746,241
<pre><code>TABWIDTH=8 def my_len(s): return len(s.expandtabs(TABWIDTH)) def pad_with_tabs(s,maxlen): return s+"\t"*((maxlen-len(s)-1)/TABWIDTH+1) </code></pre> <p>Why did I use <code>expandtabs()</code>?<br> Well it's fast</p> <pre><code>$ python -m timeit '"Bear\tnecessities\t".expandtabs()' 1000000 loops, ...
6
2009-11-17T02:34:14Z
[ "python", "function", "padding", "tabstop" ]
Python tabstop-aware len() and padding functions
1,746,116
<p>Python's len() and padding functions like string.ljust() are not tabstop-aware, i.e. they treat '\t' like any other single-width character, and don't round len up to the nearest multiple of tabstop. Example: </p> <pre><code>len('Bear\tnecessities\t') </code></pre> <p>is 17 instead of 24 ( i.e. 4+(8-4)+11+(8-3) )</...
2
2009-11-17T01:54:07Z
1,749,315
<p><code>TABWIDTH * int( math.ceil(len(s)*1.0/TABWIDTH) )</code> is indeed a massive over-kill; you can get the same result much more simply. For positive <code>i</code> and <code>n</code>, use:</p> <pre><code>def round_up_positive_int(i, n): return ((i + n - 1) // n) * n </code></pre> <p>This procedure works in ...
0
2009-11-17T14:37:37Z
[ "python", "function", "padding", "tabstop" ]
Python tabstop-aware len() and padding functions
1,746,116
<p>Python's len() and padding functions like string.ljust() are not tabstop-aware, i.e. they treat '\t' like any other single-width character, and don't round len up to the nearest multiple of tabstop. Example: </p> <pre><code>len('Bear\tnecessities\t') </code></pre> <p>is 17 instead of 24 ( i.e. 4+(8-4)+11+(8-3) )</...
2
2009-11-17T01:54:07Z
1,749,363
<p>I believe gnibbler's is the best for most prectical cases. But anyway, here is a naive (without accounting CR, LF etc) solution to compute the length of string without creating expanded copy:</p> <pre><code>def tab_aware_len(s, tabstop=8): pos = -1 extra_length = 0 while True: pos = s.find('\t',...
1
2009-11-17T14:46:06Z
[ "python", "function", "padding", "tabstop" ]
Regex, how to remove all non-alphanumeric except colon in a 12/24 hour timestamp?
1,746,167
<p>I have a string like: </p> <pre class="lang-none prettyprint-override"><code>Today, 3:30pm - Group Meeting to discuss "big idea" </code></pre> <p>How do you construct a regex such that after parsing it would return: </p> <pre class="lang-none prettyprint-override"><code>Today 3:30pm Group Meeting to discuss big...
4
2009-11-17T02:07:02Z
1,746,186
<p>I assume you'd like to keep spaces as well, and this implementation is in python, but it's PCRE so it should be portable.</p> <pre><code>import re x = u'Today, 3:30pm - Group Meeting to discuss "big idea"' re.sub(r'[^a-zA-Z0-9: ]', '', x) </code></pre> <p>Output: 'Today 3:30pm&nbsp;&nbsp;Group Meeting to discuss b...
1
2009-11-17T02:14:09Z
[ "python", "regex" ]
Regex, how to remove all non-alphanumeric except colon in a 12/24 hour timestamp?
1,746,167
<p>I have a string like: </p> <pre class="lang-none prettyprint-override"><code>Today, 3:30pm - Group Meeting to discuss "big idea" </code></pre> <p>How do you construct a regex such that after parsing it would return: </p> <pre class="lang-none prettyprint-override"><code>Today 3:30pm Group Meeting to discuss big...
4
2009-11-17T02:07:02Z
1,746,194
<pre><code># this: D:DD, DD:DDam/pm 12/24 hr re = r':(?=..(?&lt;!\d:\d\d))|[^a-zA-Z0-9 ](?&lt;!:)' </code></pre> <p>A colon must be preceded by at least one digit and followed by at least two digits: then it's a time. All other colons will be considered textual colons. </p> <h3>How it works</h3> <pre class="lang-n...
7
2009-11-17T02:16:29Z
[ "python", "regex" ]
Regex, how to remove all non-alphanumeric except colon in a 12/24 hour timestamp?
1,746,167
<p>I have a string like: </p> <pre class="lang-none prettyprint-override"><code>Today, 3:30pm - Group Meeting to discuss "big idea" </code></pre> <p>How do you construct a regex such that after parsing it would return: </p> <pre class="lang-none prettyprint-override"><code>Today 3:30pm Group Meeting to discuss big...
4
2009-11-17T02:07:02Z
1,746,195
<p>You can try, in Javascript:</p> <pre><code>var re = /(\W+(?!\d{2}[ap]m))/gi; var input = 'Today, 3:30pm - Group Meeting to discuss "big idea"'; alert(input.replace(re, " ")) </code></pre>
1
2009-11-17T02:16:44Z
[ "python", "regex" ]
Regex, how to remove all non-alphanumeric except colon in a 12/24 hour timestamp?
1,746,167
<p>I have a string like: </p> <pre class="lang-none prettyprint-override"><code>Today, 3:30pm - Group Meeting to discuss "big idea" </code></pre> <p>How do you construct a regex such that after parsing it would return: </p> <pre class="lang-none prettyprint-override"><code>Today 3:30pm Group Meeting to discuss big...
4
2009-11-17T02:07:02Z
1,746,301
<p>Python.</p> <pre><code>import string punct=string.punctuation s='Today, 3:30pm - Group Meeting:am to discuss "big idea" by our madam' for item in s.split(): try: t=time.strptime(item,"%H:%M%p") except: item=''.join([ i for i in item if i not in punct]) else: item=item print i...
2
2009-11-17T02:56:19Z
[ "python", "regex" ]
Regex, how to remove all non-alphanumeric except colon in a 12/24 hour timestamp?
1,746,167
<p>I have a string like: </p> <pre class="lang-none prettyprint-override"><code>Today, 3:30pm - Group Meeting to discuss "big idea" </code></pre> <p>How do you construct a regex such that after parsing it would return: </p> <pre class="lang-none prettyprint-override"><code>Today 3:30pm Group Meeting to discuss big...
4
2009-11-17T02:07:02Z
1,746,620
<blockquote> <blockquote> <blockquote> <p>s="Call me, my dear, at 3:30"</p> <p>re.sub(r'[^\w :]','',s)</p> </blockquote> </blockquote> </blockquote> <p>'Call me my dear at 3:30'</p>
-1
2009-11-17T04:39:23Z
[ "python", "regex" ]
Regex, how to remove all non-alphanumeric except colon in a 12/24 hour timestamp?
1,746,167
<p>I have a string like: </p> <pre class="lang-none prettyprint-override"><code>Today, 3:30pm - Group Meeting to discuss "big idea" </code></pre> <p>How do you construct a regex such that after parsing it would return: </p> <pre class="lang-none prettyprint-override"><code>Today 3:30pm Group Meeting to discuss big...
4
2009-11-17T02:07:02Z
36,383,979
<p>Correct regexp to do that would be:</p> <pre><code>'(?&lt;!\d):|:(?!\d\d)|[^a-zA-Z0-9 :]' </code></pre>
0
2016-04-03T09:58:18Z
[ "python", "regex" ]
Why won't my Python scatter plot work?
1,746,312
<p>I created a very simple scatter plot using pylab.</p> <pre><code>pylab.scatter(engineSize, fuelMile) pylab.show() </code></pre> <p>The rest of the program isn't worth posting, because it's that line that's giving me the problem. When I change "scatter" to "plot" it graphs the data, but each point is part of a line...
5
2009-11-17T02:58:32Z
1,843,582
<p>Okay, so since this works, something must be wrong with your inputs. Clearly you need to post more, unless this "answer" solves your problem:</p> <pre><code>&gt;&gt;&gt; import pylab &gt;&gt;&gt; pylab.scatter([500, 550, 700, 1100], [5.5, 6.5, 3.1, 9.7]) &lt;matplotlib.collections.RegularPolyCollection object at 0...
2
2009-12-03T22:48:54Z
[ "python", "graph", "matplotlib", "scatter" ]
Why won't my Python scatter plot work?
1,746,312
<p>I created a very simple scatter plot using pylab.</p> <pre><code>pylab.scatter(engineSize, fuelMile) pylab.show() </code></pre> <p>The rest of the program isn't worth posting, because it's that line that's giving me the problem. When I change "scatter" to "plot" it graphs the data, but each point is part of a line...
5
2009-11-17T02:58:32Z
2,367,735
<p>I bet engineSize, fuelMile are stings, try printing them, if that is the case, you have to convert them to float before passing them as arguments to scatter</p> <pre><code>floatval = float(strval) </code></pre>
9
2010-03-02T23:31:58Z
[ "python", "graph", "matplotlib", "scatter" ]
python csv headers
1,746,489
<p>I have set of csv headers that i am trying to match with uploads, it's not really working. Not all headers are required, just have to match what's in file</p> <pre> reader = csv.DictReader(open(PathFile)) headers = reader.fieldnames for header in sorted(set(headers)): if (header == 'ip') or (h...
13
2009-11-17T03:59:55Z
1,746,549
<p>I am not exactly sure what you want to achieve but if you simply want to know if some columns is in CSV, and you are sure that all rows have same columns, and you want to use dict reader use this</p> <pre><code>s="""col1,col2,col3 ok,ok,ok hmm,hmm,hmm cool,cool,cool""" import csv reader = csv.DictReader(s.split("...
5
2009-11-17T04:17:58Z
[ "python", "csv" ]
python csv headers
1,746,489
<p>I have set of csv headers that i am trying to match with uploads, it's not really working. Not all headers are required, just have to match what's in file</p> <pre> reader = csv.DictReader(open(PathFile)) headers = reader.fieldnames for header in sorted(set(headers)): if (header == 'ip') or (h...
13
2009-11-17T03:59:55Z
1,746,622
<p>Based on your edit, you need to <a href="http://docs.python.org/library/csv.html#csv.Dialect.skipinitialspace">skip the initial space</a> after the comma.</p> <p>This should do it:</p> <pre><code>&gt;&gt;&gt; reader = csv.DictReader(open(PathFile),skipinitialspace=True) </code></pre>
9
2009-11-17T04:39:34Z
[ "python", "csv" ]
Bitwise operation and usage
1,746,613
<p>Consider this code:</p> <pre><code>x = 1 # 0001 x &lt;&lt; 2 # Shift left 2 bits: 0100 # Result: 4 x | 2 # Bitwise OR: 0011 # Result: 3 x &amp; 1 # Bitwise AND: 0001 # Result: 1 </code></pre> <p>I can understand the arithmetic operators in Python (and other languages), but I never unde...
58
2009-11-17T04:37:05Z
1,746,639
<p>One typical usage:</p> <p><code>|</code> is used to set a certain bit to 1</p> <p><code>&amp;</code> is used to test or clear a certain bit </p> <ul> <li><p>Set a bit (where n is the bit number, and 0 is the least significant bit):</p> <p><code>unsigned char a |= (1 &lt;&lt; n);</code></p></li> <li><p>Clear a bi...
28
2009-11-17T04:43:46Z
[ "python", "binary", "operators", "bit-manipulation" ]
Bitwise operation and usage
1,746,613
<p>Consider this code:</p> <pre><code>x = 1 # 0001 x &lt;&lt; 2 # Shift left 2 bits: 0100 # Result: 4 x | 2 # Bitwise OR: 0011 # Result: 3 x &amp; 1 # Bitwise AND: 0001 # Result: 1 </code></pre> <p>I can understand the arithmetic operators in Python (and other languages), but I never unde...
58
2009-11-17T04:37:05Z
1,746,642
<p>Bitwise operators are operators that work on multi-bit values, but conceptually one bit at a time.</p> <ul> <li><code>AND</code> is 1 only if <em>both</em> of its inputs are 1, otherwise it's 0.</li> <li><code>OR</code> is 1 if <em>one or both</em> of its inputs are 1, otherwise it's 0.</li> <li><code>XOR</code> is...
92
2009-11-17T04:44:42Z
[ "python", "binary", "operators", "bit-manipulation" ]
Bitwise operation and usage
1,746,613
<p>Consider this code:</p> <pre><code>x = 1 # 0001 x &lt;&lt; 2 # Shift left 2 bits: 0100 # Result: 4 x | 2 # Bitwise OR: 0011 # Result: 3 x &amp; 1 # Bitwise AND: 0001 # Result: 1 </code></pre> <p>I can understand the arithmetic operators in Python (and other languages), but I never unde...
58
2009-11-17T04:37:05Z
1,746,648
<p>I hope this clarifies those two:</p> <pre><code>x | 2 0001 //x 0010 //2 0011 //result = 3 </code></pre> <hr> <pre><code>x &amp; 1 0001 //x 0001 //1 0001 //result = 1 </code></pre>
5
2009-11-17T04:46:02Z
[ "python", "binary", "operators", "bit-manipulation" ]
Bitwise operation and usage
1,746,613
<p>Consider this code:</p> <pre><code>x = 1 # 0001 x &lt;&lt; 2 # Shift left 2 bits: 0100 # Result: 4 x | 2 # Bitwise OR: 0011 # Result: 3 x &amp; 1 # Bitwise AND: 0001 # Result: 1 </code></pre> <p>I can understand the arithmetic operators in Python (and other languages), but I never unde...
58
2009-11-17T04:37:05Z
1,746,710
<p>Think of 0 as false and 1 as true. Then bitwise and(&amp;) and or(|) work just like regular and and or except they do all of the bits in the value at once. Typically you will see them used for flags if you have 30 options that can be set (say as draw styles on a window) you don't want to have to pass in 30 separat...
3
2009-11-17T05:05:21Z
[ "python", "binary", "operators", "bit-manipulation" ]
Bitwise operation and usage
1,746,613
<p>Consider this code:</p> <pre><code>x = 1 # 0001 x &lt;&lt; 2 # Shift left 2 bits: 0100 # Result: 4 x | 2 # Bitwise OR: 0011 # Result: 3 x &amp; 1 # Bitwise AND: 0001 # Result: 1 </code></pre> <p>I can understand the arithmetic operators in Python (and other languages), but I never unde...
58
2009-11-17T04:37:05Z
1,746,850
<blockquote> <p>what are bitwise operators actually used for? I'd appreciate some examples.</p> </blockquote> <p>One of the most common uses of bitwise operations is for parsing hexadecimal colours.</p> <p>For example, here's a <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29" rel="nofollow">...
22
2009-11-17T05:47:59Z
[ "python", "binary", "operators", "bit-manipulation" ]
Bitwise operation and usage
1,746,613
<p>Consider this code:</p> <pre><code>x = 1 # 0001 x &lt;&lt; 2 # Shift left 2 bits: 0100 # Result: 4 x | 2 # Bitwise OR: 0011 # Result: 3 x &amp; 1 # Bitwise AND: 0001 # Result: 1 </code></pre> <p>I can understand the arithmetic operators in Python (and other languages), but I never unde...
58
2009-11-17T04:37:05Z
11,872,647
<p>Another common use-case is manipulating/testing file permissions. See the Python stat module: <a href="http://docs.python.org/library/stat.html" rel="nofollow">http://docs.python.org/library/stat.html</a>.</p> <p>For example, to compare a file's permissions to a desired permission set, you could do something like:...
1
2012-08-08T20:29:34Z
[ "python", "binary", "operators", "bit-manipulation" ]
Bitwise operation and usage
1,746,613
<p>Consider this code:</p> <pre><code>x = 1 # 0001 x &lt;&lt; 2 # Shift left 2 bits: 0100 # Result: 4 x | 2 # Bitwise OR: 0011 # Result: 3 x &amp; 1 # Bitwise AND: 0001 # Result: 1 </code></pre> <p>I can understand the arithmetic operators in Python (and other languages), but I never unde...
58
2009-11-17T04:37:05Z
14,329,627
<p>I didn't see it mentioned above but you will also see some people use left and right shift for arithmetic operations. A left shift by x is equivalent to multiplying by 2^x (as long as it doesn't overflow) and a right shift is equivalent to dividing by 2^x.</p> <p>Recently I've seen people using x &lt;&lt; 1 and x...
3
2013-01-15T01:11:07Z
[ "python", "binary", "operators", "bit-manipulation" ]
Bitwise operation and usage
1,746,613
<p>Consider this code:</p> <pre><code>x = 1 # 0001 x &lt;&lt; 2 # Shift left 2 bits: 0100 # Result: 4 x | 2 # Bitwise OR: 0011 # Result: 3 x &amp; 1 # Bitwise AND: 0001 # Result: 1 </code></pre> <p>I can understand the arithmetic operators in Python (and other languages), but I never unde...
58
2009-11-17T04:37:05Z
15,239,663
<p>Bit representations of integers are often used in scientific computing to represent arrays of true-false information because a bitwise operation is much faster than iterating through an array of booleans. (Higher level languages may use the idea of a bit array.)</p> <p>A nice and fairly simple example of this is th...
2
2013-03-06T05:29:27Z
[ "python", "binary", "operators", "bit-manipulation" ]
Bitwise operation and usage
1,746,613
<p>Consider this code:</p> <pre><code>x = 1 # 0001 x &lt;&lt; 2 # Shift left 2 bits: 0100 # Result: 4 x | 2 # Bitwise OR: 0011 # Result: 3 x &amp; 1 # Bitwise AND: 0001 # Result: 1 </code></pre> <p>I can understand the arithmetic operators in Python (and other languages), but I never unde...
58
2009-11-17T04:37:05Z
17,847,497
<p>This example will show you the operations for all four 2 bit values:</p> <pre><code>10 | 12 1010 #decimal 10 1100 #decimal 12 1110 #result = 14 </code></pre> <hr> <pre><code>10 &amp; 12 1010 #decimal 10 1100 #decimal 12 1000 #result = 8 </code></pre> <p>Here is one example of usage:</p> <pre><code>x = raw_i...
3
2013-07-25T01:28:22Z
[ "python", "binary", "operators", "bit-manipulation" ]
Bitwise operation and usage
1,746,613
<p>Consider this code:</p> <pre><code>x = 1 # 0001 x &lt;&lt; 2 # Shift left 2 bits: 0100 # Result: 4 x | 2 # Bitwise OR: 0011 # Result: 3 x &amp; 1 # Bitwise AND: 0001 # Result: 1 </code></pre> <p>I can understand the arithmetic operators in Python (and other languages), but I never unde...
58
2009-11-17T04:37:05Z
22,020,899
<p>I think that the second part of the question: </p> <blockquote> <p>Also, what are bitwise operators actually used for? I'd appreciate some examples.</p> </blockquote> <p>Has been only partially addressed. These are my two cents on that matter. </p> <p>Bitwise operations in programming languages play a fundamen...
2
2014-02-25T16:52:44Z
[ "python", "binary", "operators", "bit-manipulation" ]
Bitwise operation and usage
1,746,613
<p>Consider this code:</p> <pre><code>x = 1 # 0001 x &lt;&lt; 2 # Shift left 2 bits: 0100 # Result: 4 x | 2 # Bitwise OR: 0011 # Result: 3 x &amp; 1 # Bitwise AND: 0001 # Result: 1 </code></pre> <p>I can understand the arithmetic operators in Python (and other languages), but I never unde...
58
2009-11-17T04:37:05Z
22,582,612
<p>There may be a better way to find where an array element is between two values, but as this example shows, the <strong><em>&amp;</em></strong> works here, whereas <strong><em>and</em></strong> does not.</p> <pre><code>import numpy as np a=np.array([1.2, 2.3, 3.4]) np.where((a&gt;2) and (a&lt;3)) #Result: Valu...
1
2014-03-22T19:42:50Z
[ "python", "binary", "operators", "bit-manipulation" ]
Bitwise operation and usage
1,746,613
<p>Consider this code:</p> <pre><code>x = 1 # 0001 x &lt;&lt; 2 # Shift left 2 bits: 0100 # Result: 4 x | 2 # Bitwise OR: 0011 # Result: 3 x &amp; 1 # Bitwise AND: 0001 # Result: 1 </code></pre> <p>I can understand the arithmetic operators in Python (and other languages), but I never unde...
58
2009-11-17T04:37:05Z
34,910,466
<p>i didnt see it mentioned, This example will show you the (-) decimal operation for 2 bit values: A-B (only if A contains B)</p> <p>this operation is needed when we hold an verb in our program that represent bits. sometimes we need to add bits (like above) and sometimes we need to remove bits (if the verb contains t...
0
2016-01-20T21:03:30Z
[ "python", "binary", "operators", "bit-manipulation" ]
Bitwise operation and usage
1,746,613
<p>Consider this code:</p> <pre><code>x = 1 # 0001 x &lt;&lt; 2 # Shift left 2 bits: 0100 # Result: 4 x | 2 # Bitwise OR: 0011 # Result: 3 x &amp; 1 # Bitwise AND: 0001 # Result: 1 </code></pre> <p>I can understand the arithmetic operators in Python (and other languages), but I never unde...
58
2009-11-17T04:37:05Z
37,182,716
<p>Whilst manipulating bits of an integer is useful, often for network protocols, which may be specified down to the bit, one can require manipulation of longer byte sequences (which aren't easily converted into one integer). In this case it is useful to employ the <a href="http://pythonhosted.org/bitstring/" rel="nofo...
0
2016-05-12T09:27:02Z
[ "python", "binary", "operators", "bit-manipulation" ]
Minimal Python Installation
1,746,818
<p>Various software installations on my laptop each require their own particular version of Python. ViewVC requires Python 2.5 and Blender requires Python 2.6. Mercurial (thankfully) comes with its Python interpreter packaged in a DLL in the Mercurial installation itself.</p> <p>How do I get by without having to insta...
0
2009-11-17T05:37:18Z
1,746,859
<p>You should be able to get away with installing the Python binaries in the same tree as the specific application I believe (Totally untested hunch though).</p>
0
2009-11-17T05:50:29Z
[ "python" ]
Minimal Python Installation
1,746,818
<p>Various software installations on my laptop each require their own particular version of Python. ViewVC requires Python 2.5 and Blender requires Python 2.6. Mercurial (thankfully) comes with its Python interpreter packaged in a DLL in the Mercurial installation itself.</p> <p>How do I get by without having to insta...
0
2009-11-17T05:37:18Z
1,746,927
<p>It's hard to know which "bare minimum" the Blender scripts you'll want to use in the future may be counting on (short of the full Python standard library, which isn't all that large in term of disk space after all). Why not install both Python 2.5 and 2.6? They can coexist nicely (if your scriptable apps use hashb...
2
2009-11-17T06:14:51Z
[ "python" ]
Python ValueError: insecure string pickle
1,746,825
<p>PWhen I am trying to load something I dumped using cPickle, I get the error message:</p> <pre><code>ValueError: insecure string pickle </code></pre> <p>Both the dumping and loading work are done on the same computer, thus same OS: Ubuntu 8.04.</p> <p>How could I solve this problem?</p>
30
2009-11-17T05:39:44Z
1,746,919
<p>Check <a href="http://mail.python.org/pipermail/python-list/2007-September/465169.html">this thread</a>. Peter Otten says:</p> <blockquote> <p>A corrupted pickle. The error is raised if a string in the dump does not both start and end with " or '.</p> </blockquote> <p>and shows a simple way to reproduce suc...
6
2009-11-17T06:10:53Z
[ "python", "pickle" ]
Python ValueError: insecure string pickle
1,746,825
<p>PWhen I am trying to load something I dumped using cPickle, I get the error message:</p> <pre><code>ValueError: insecure string pickle </code></pre> <p>Both the dumping and loading work are done on the same computer, thus same OS: Ubuntu 8.04.</p> <p>How could I solve this problem?</p>
30
2009-11-17T05:39:44Z
1,749,405
<p>What are you doing with data between <code>dump()</code> and <code>load()</code>? It's quite common error to store pickled data in file opened in text mode (on Windows) or in database storage in the way that doesn't work properly for binary data (VARCHAR, TEXT columns in some databases, some key-value storages). Try...
5
2009-11-17T14:54:34Z
[ "python", "pickle" ]
Python ValueError: insecure string pickle
1,746,825
<p>PWhen I am trying to load something I dumped using cPickle, I get the error message:</p> <pre><code>ValueError: insecure string pickle </code></pre> <p>Both the dumping and loading work are done on the same computer, thus same OS: Ubuntu 8.04.</p> <p>How could I solve this problem?</p>
30
2009-11-17T05:39:44Z
13,395,516
<p>"are much more likely than a never-observed bug in Python itself in a functionality that's used billions of times a day all over the world": it always amazes me how cross people get in these forums.</p> <p>One easy way to get this problem is by forgetting to close the stream that you're using for dumping the data s...
60
2012-11-15T10:25:42Z
[ "python", "pickle" ]
Python ValueError: insecure string pickle
1,746,825
<p>PWhen I am trying to load something I dumped using cPickle, I get the error message:</p> <pre><code>ValueError: insecure string pickle </code></pre> <p>Both the dumping and loading work are done on the same computer, thus same OS: Ubuntu 8.04.</p> <p>How could I solve this problem?</p>
30
2009-11-17T05:39:44Z
21,709,187
<p>I got the <code>Python ValueError: insecure string pickle</code> message in a different way.</p> <p>For me it happened after a <code>base64</code> encoding a binary file and passing through <code>urllib2</code> sockets.</p> <p><strong>Initially I was wrapping up a file like this</strong></p> <pre><code>with open(...
1
2014-02-11T17:45:05Z
[ "python", "pickle" ]
Python ValueError: insecure string pickle
1,746,825
<p>PWhen I am trying to load something I dumped using cPickle, I get the error message:</p> <pre><code>ValueError: insecure string pickle </code></pre> <p>Both the dumping and loading work are done on the same computer, thus same OS: Ubuntu 8.04.</p> <p>How could I solve this problem?</p>
30
2009-11-17T05:39:44Z
25,544,706
<p>Same problem with a file that was made with python on windows, and reloaded with python on linux. Solution : dos2unix on the file before reading in linux : works as a charm !</p>
2
2014-08-28T08:56:29Z
[ "python", "pickle" ]
Python ValueError: insecure string pickle
1,746,825
<p>PWhen I am trying to load something I dumped using cPickle, I get the error message:</p> <pre><code>ValueError: insecure string pickle </code></pre> <p>Both the dumping and loading work are done on the same computer, thus same OS: Ubuntu 8.04.</p> <p>How could I solve this problem?</p>
30
2009-11-17T05:39:44Z
32,294,233
<p>I've get this error in Python 2.7 because of open mode 'rb':</p> <pre><code> with open(path_to_file, 'rb') as pickle_file: obj = pickle.load(pickle_file) </code></pre> <p>So, for Python 2 'mode' should be 'r'</p> <p>Also, I've wondered that Python 3 doesn't support pickle format of Python 2, and in cas...
0
2015-08-30T07:23:12Z
[ "python", "pickle" ]
Python ValueError: insecure string pickle
1,746,825
<p>PWhen I am trying to load something I dumped using cPickle, I get the error message:</p> <pre><code>ValueError: insecure string pickle </code></pre> <p>Both the dumping and loading work are done on the same computer, thus same OS: Ubuntu 8.04.</p> <p>How could I solve this problem?</p>
30
2009-11-17T05:39:44Z
38,728,603
<p>This is what happened to me, might be a small section of population, but I want to put this out here nevertheless, for them:</p> <p>Interpreter (Python3) would have given you an error saying it required the input file stream to be in bytes, and not as a string, and you may have changed the open mode argument from '...
0
2016-08-02T19:06:20Z
[ "python", "pickle" ]
Python ValueError: insecure string pickle
1,746,825
<p>PWhen I am trying to load something I dumped using cPickle, I get the error message:</p> <pre><code>ValueError: insecure string pickle </code></pre> <p>Both the dumping and loading work are done on the same computer, thus same OS: Ubuntu 8.04.</p> <p>How could I solve this problem?</p>
30
2009-11-17T05:39:44Z
40,115,777
<p>This error may also occur with python 2 (and early versions of python 3) if your pickle is large (<a href="http://bugs.python.org/issue11564" rel="nofollow">Python Issue #11564</a>):</p> <pre><code>Python 2.7.11 |Anaconda custom (64-bit)| (default, Dec 6 2015, 18:08:32) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on l...
0
2016-10-18T18:44:03Z
[ "python", "pickle" ]
Django manage.py syncdb throwing No module named MySQLdb
1,746,863
<p>I am a newbie learning Python/Django...</p> <p>Am using the following tutorial located <a href="http://docs.djangoproject.com/en/dev/intro/tutorial01/#intro-tutorial01">here</a>.</p> <p>Created a mysite database in MySQL 5 running on Snow Leopard.</p> <p>Edited the settings.py file to look like this:</p> <pre><c...
10
2009-11-17T05:52:15Z
1,746,890
<p>The problem is that you are missing the Python module that interfaces with MySQL.</p> <p>See the Django docs for <a href="http://docs.djangoproject.com/en/dev/topics/install/#get-your-database-running">get your database running</a> which further points to <a href="http://docs.djangoproject.com/en/dev/ref/databases/...
12
2009-11-17T06:01:22Z
[ "python", "mysql", "django", "osx", "osx-snow-leopard" ]
Django manage.py syncdb throwing No module named MySQLdb
1,746,863
<p>I am a newbie learning Python/Django...</p> <p>Am using the following tutorial located <a href="http://docs.djangoproject.com/en/dev/intro/tutorial01/#intro-tutorial01">here</a>.</p> <p>Created a mysite database in MySQL 5 running on Snow Leopard.</p> <p>Edited the settings.py file to look like this:</p> <pre><c...
10
2009-11-17T05:52:15Z
1,749,102
<pre><code>sudo easy_install mysql-python </code></pre> <p>will install the MySQLdb module to allow you to work with MySQL from Python, or, if you want to work with virtualenv (which you should),</p> <pre><code>sudo easy_install virtualenv virtualenvwrapper export WORKON_HOME=$HOME/.virtualenvs export PIP_VIRTUALENV_...
14
2009-11-17T14:01:53Z
[ "python", "mysql", "django", "osx", "osx-snow-leopard" ]
Django manage.py syncdb throwing No module named MySQLdb
1,746,863
<p>I am a newbie learning Python/Django...</p> <p>Am using the following tutorial located <a href="http://docs.djangoproject.com/en/dev/intro/tutorial01/#intro-tutorial01">here</a>.</p> <p>Created a mysite database in MySQL 5 running on Snow Leopard.</p> <p>Edited the settings.py file to look like this:</p> <pre><c...
10
2009-11-17T05:52:15Z
13,165,804
<p>It's worth pointing out (even at this late date) that the "ImproperlyConfigured" error below</p> <blockquote> <p>File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages /django/db/backends/mysql/base.py", line 13, in <br> raise ImproperlyConfigured("Error loading MySQLdb module...
2
2012-10-31T19:00:53Z
[ "python", "mysql", "django", "osx", "osx-snow-leopard" ]
Django manage.py syncdb throwing No module named MySQLdb
1,746,863
<p>I am a newbie learning Python/Django...</p> <p>Am using the following tutorial located <a href="http://docs.djangoproject.com/en/dev/intro/tutorial01/#intro-tutorial01">here</a>.</p> <p>Created a mysite database in MySQL 5 running on Snow Leopard.</p> <p>Edited the settings.py file to look like this:</p> <pre><c...
10
2009-11-17T05:52:15Z
23,076,300
<p>Try this if you are using</p> <p>linux:- <code>sudo apt-get install python-mysqldb</code></p> <p>windows:- <code>pip install python-mysqldb</code> or <code>easy_install python-mysqldb</code></p> <p>Hope this should work</p>
1
2014-04-15T06:41:52Z
[ "python", "mysql", "django", "osx", "osx-snow-leopard" ]
Django manage.py syncdb throwing No module named MySQLdb
1,746,863
<p>I am a newbie learning Python/Django...</p> <p>Am using the following tutorial located <a href="http://docs.djangoproject.com/en/dev/intro/tutorial01/#intro-tutorial01">here</a>.</p> <p>Created a mysite database in MySQL 5 running on Snow Leopard.</p> <p>Edited the settings.py file to look like this:</p> <pre><c...
10
2009-11-17T05:52:15Z
31,098,616
<p>Make sure to create your database and with your MySQL server running try to connect to the database to check that database name, username and password are correct. then run:</p> <p>1) <code>pip install mysqlclient</code></p> <p>2) <code>python manage.py migrate</code></p>
0
2015-06-28T10:17:24Z
[ "python", "mysql", "django", "osx", "osx-snow-leopard" ]
Is Java or Python better for writing a web-page-source-checking web service on Google App Engines?
1,746,867
<p>I hope you all have a nice day.</p> <p>I want to write a web service that would check some web page HTML code every 20 minutes and e-mail it to my mail box. <a href="http://stackoverflow.com/questions/1735028/is-it-possible-to-have-a-free-web-service-that-would-check-a-page-and-email-its-h">Here</a> I was given a s...
3
2009-11-17T05:53:57Z
1,746,907
<p>Both the languages and their App Engine implementations are pretty solid and mature. As a language, Python is faster to learn, but Java comes with richer tools such as Eclipse that may partly compensate. A lot depends on what other languages you have background in -- for example, coming from C#, Java would be simp...
5
2009-11-17T06:05:55Z
[ "java", "python", "html", "web-services", "google-app-engine" ]
Is Java or Python better for writing a web-page-source-checking web service on Google App Engines?
1,746,867
<p>I hope you all have a nice day.</p> <p>I want to write a web service that would check some web page HTML code every 20 minutes and e-mail it to my mail box. <a href="http://stackoverflow.com/questions/1735028/is-it-possible-to-have-a-free-web-service-that-would-check-a-page-and-email-its-h">Here</a> I was given a s...
3
2009-11-17T05:53:57Z
1,746,929
<p>I've tried both languages with GAE and here's my general feeling about the choice of language for it: </p> <ul> <li><p>Python is generally simpler. So, if you're using bare GAE API, Python's one is simpler to learn and simpler to write a webapp in it.</p></li> <li><p>Java is more compatible. Python's API is general...
3
2009-11-17T06:16:10Z
[ "java", "python", "html", "web-services", "google-app-engine" ]
Is Java or Python better for writing a web-page-source-checking web service on Google App Engines?
1,746,867
<p>I hope you all have a nice day.</p> <p>I want to write a web service that would check some web page HTML code every 20 minutes and e-mail it to my mail box. <a href="http://stackoverflow.com/questions/1735028/is-it-possible-to-have-a-free-web-service-that-would-check-a-page-and-email-its-h">Here</a> I was given a s...
3
2009-11-17T05:53:57Z
1,747,449
<p>For your particular task, I'd suggest Python, mostly because of the existence of <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">Beautiful Soup</a>, an excellent HTML parser that handles poorly formed documents.</p>
2
2009-11-17T08:55:11Z
[ "java", "python", "html", "web-services", "google-app-engine" ]
python reduce error?
1,746,999
<p>The following is my python code:</p> <pre><code>&gt;&gt;&gt; item = 1 &gt;&gt;&gt; a = [] &gt;&gt;&gt; a.append((1,2,3)) &gt;&gt;&gt; a.append((7,2,4)) &gt;&gt;&gt; sums=reduce(lambda x:abs(item-x[1]),a) Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: &lt;lambda&gt;()...
2
2009-11-17T06:37:30Z
1,747,015
<p>Your lambda takes only one argument, but <code>reduce</code> requires a function that takes two arguments. Make your lambda take two arguments.</p> <p>Since you didn't say what you want this code to do, I'll just guess:</p> <pre><code>the_sum=reduce(lambda x,y:abs(y[1]-x[1]),a) </code></pre>
7
2009-11-17T06:42:49Z
[ "python", "lambda", "arguments", "reduce" ]
python reduce error?
1,746,999
<p>The following is my python code:</p> <pre><code>&gt;&gt;&gt; item = 1 &gt;&gt;&gt; a = [] &gt;&gt;&gt; a.append((1,2,3)) &gt;&gt;&gt; a.append((7,2,4)) &gt;&gt;&gt; sums=reduce(lambda x:abs(item-x[1]),a) Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: &lt;lambda&gt;()...
2
2009-11-17T06:37:30Z
1,747,070
<p><code>reduce</code> expects the function it is given to accept 2 arguments. For every item in the iterable it will pass the function the current item, and the previous return value from the function. So, getting the sum of a list is <code>reduce(lambda: x,y: x+y, l, 0)</code></p> <p>If I understand correctly, to ge...
2
2009-11-17T06:59:15Z
[ "python", "lambda", "arguments", "reduce" ]
python reduce error?
1,746,999
<p>The following is my python code:</p> <pre><code>&gt;&gt;&gt; item = 1 &gt;&gt;&gt; a = [] &gt;&gt;&gt; a.append((1,2,3)) &gt;&gt;&gt; a.append((7,2,4)) &gt;&gt;&gt; sums=reduce(lambda x:abs(item-x[1]),a) Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: &lt;lambda&gt;()...
2
2009-11-17T06:37:30Z
1,747,321
<p>Your problem itself is a bit unclear. Anyway, i have taken just assumption--</p> <pre><code>&gt;&gt;&gt; a = [] &gt;&gt;&gt; a.append((1,2,3)) &gt;&gt;&gt; a.append((7,2,4)) &gt;&gt;&gt; a [(1, 2, 3), (7, 2, 4)] # list of tuples </code></pre> <p>I am assuming that you might be interested in getting the sum of all ...
3
2009-11-17T08:14:46Z
[ "python", "lambda", "arguments", "reduce" ]
How to kill headless X server started via Python?
1,747,022
<p>I want to get screenshots of a webpage in Python. For this I am using <a href="http://github.com/AdamN/python-webkit2png/" rel="nofollow">http://github.com/AdamN/python-webkit2png/</a> .</p> <pre><code> newArgs = ["xvfb-run", "--server-args=-screen 0, 640x480x24", sys.argv[0]] for i in range(1, len(sys.argv)...
2
2009-11-17T06:46:46Z
1,755,442
<p>The documentation for <a href="http://docs.python.org/3.1/library/os.html#os.execvp" rel="nofollow"><code>os.execvp</code></a> states:</p> <blockquote> <p>These functions all execute a new program, replacing the current process; they do not return. [..]</p> </blockquote> <p>So after calling <code>os.execvp<...
4
2009-11-18T11:41:38Z
[ "python", "screenshot", "xserver" ]
Sum and Division example (Python)
1,747,130
<pre><code>&gt;&gt;&gt; sum((1, 2, 3, 4, 5, 6, 7)) 28 &gt;&gt;&gt; 28/7 4.0 &gt;&gt;&gt; sum((1,2,3,4,5,6,7,8,9,10,11,12,13,14)) 105 &gt;&gt;&gt; 105/7 15.0 &gt;&gt;&gt; </code></pre> <p>How do I automate this sum and division using a loop maybe?</p> <p>Edit: Maybe I wasn't clear - I want a loop to keep doing the sum...
1
2009-11-17T07:16:10Z
1,747,145
<p>The direct answer:</p> <pre><code>def sum_to_number_divided_by_seven(i): return sum(range(i+1)) / 7 </code></pre> <p>The more efficient answer:</p> <pre><code>def sum_to_number_divided_by_seven(i): return (i*(i+1))/14 </code></pre>
5
2009-11-17T07:20:16Z
[ "python", "sum", "division" ]
Sum and Division example (Python)
1,747,130
<pre><code>&gt;&gt;&gt; sum((1, 2, 3, 4, 5, 6, 7)) 28 &gt;&gt;&gt; 28/7 4.0 &gt;&gt;&gt; sum((1,2,3,4,5,6,7,8,9,10,11,12,13,14)) 105 &gt;&gt;&gt; 105/7 15.0 &gt;&gt;&gt; </code></pre> <p>How do I automate this sum and division using a loop maybe?</p> <p>Edit: Maybe I wasn't clear - I want a loop to keep doing the sum...
1
2009-11-17T07:16:10Z
1,747,158
<p>I'm not sure what you want, but maybe it is something like:</p> <pre><code>sum(range(x*7+1))/7 </code></pre>
0
2009-11-17T07:25:29Z
[ "python", "sum", "division" ]
Sum and Division example (Python)
1,747,130
<pre><code>&gt;&gt;&gt; sum((1, 2, 3, 4, 5, 6, 7)) 28 &gt;&gt;&gt; 28/7 4.0 &gt;&gt;&gt; sum((1,2,3,4,5,6,7,8,9,10,11,12,13,14)) 105 &gt;&gt;&gt; 105/7 15.0 &gt;&gt;&gt; </code></pre> <p>How do I automate this sum and division using a loop maybe?</p> <p>Edit: Maybe I wasn't clear - I want a loop to keep doing the sum...
1
2009-11-17T07:16:10Z
1,747,258
<p>My version: </p> <pre><code>def sum_of_nums_divided_by_7(num): return reduce(lambda x, y: x+y, range(num)) / 7 </code></pre>
0
2009-11-17T07:57:26Z
[ "python", "sum", "division" ]
Sum and Division example (Python)
1,747,130
<pre><code>&gt;&gt;&gt; sum((1, 2, 3, 4, 5, 6, 7)) 28 &gt;&gt;&gt; 28/7 4.0 &gt;&gt;&gt; sum((1,2,3,4,5,6,7,8,9,10,11,12,13,14)) 105 &gt;&gt;&gt; 105/7 15.0 &gt;&gt;&gt; </code></pre> <p>How do I automate this sum and division using a loop maybe?</p> <p>Edit: Maybe I wasn't clear - I want a loop to keep doing the sum...
1
2009-11-17T07:16:10Z
1,747,297
<p>if i understand your problem correctly. You want to be able to accept user input - x, and then sum values 1-7 then devide by 7, if the qoutient is higher than x stop there, otherwise continue to sum up 1-14, devide by 7 and check that quotient - and continute in multiples of 7?</p> <p>My easy sollution is</p> <pre...
0
2009-11-17T08:09:51Z
[ "python", "sum", "division" ]
Sum and Division example (Python)
1,747,130
<pre><code>&gt;&gt;&gt; sum((1, 2, 3, 4, 5, 6, 7)) 28 &gt;&gt;&gt; 28/7 4.0 &gt;&gt;&gt; sum((1,2,3,4,5,6,7,8,9,10,11,12,13,14)) 105 &gt;&gt;&gt; 105/7 15.0 &gt;&gt;&gt; </code></pre> <p>How do I automate this sum and division using a loop maybe?</p> <p>Edit: Maybe I wasn't clear - I want a loop to keep doing the sum...
1
2009-11-17T07:16:10Z
1,747,302
<pre><code>def sumdiv7(limit): for i in range(limit): result = sum(range(i*7)) / 7 print "For", i, ", sumdiv = ", result </code></pre> <p>Example:</p> <pre><code>&gt;&gt;&gt; sumdiv7(4) For 0 , sumdiv = 0 For 1 , sumdiv = 3 For 2 , sumdiv = 13 For 3 , sumdiv = 30 </code></pre> <p>The trick is...
1
2009-11-17T08:11:06Z
[ "python", "sum", "division" ]
Google Wave Python Tutorial - What next?
1,747,198
<p>I just finished working through Google's <a href="http://code.google.com/apis/wave/extensions/robots/python-tutorial.html" rel="nofollow">Wave Robot: Python Tutorial</a>. The <a href="http://wave-robot-python-client.googlecode.com/svn/trunk/pydocs/index.html" rel="nofollow">API Reference</a> looks a bit imposing. Is...
3
2009-11-17T07:37:08Z
1,747,667
<p>Building the robot is fairly straight forward conceptually. The Python API itself however is buggy and hard to work with.</p> <p>Were you able to build a simple robot that responds to commands? That's a start IMHO.</p>
1
2009-11-17T09:42:24Z
[ "python", "google-app-engine", "google-wave" ]
Google Wave Python Tutorial - What next?
1,747,198
<p>I just finished working through Google's <a href="http://code.google.com/apis/wave/extensions/robots/python-tutorial.html" rel="nofollow">Wave Robot: Python Tutorial</a>. The <a href="http://wave-robot-python-client.googlecode.com/svn/trunk/pydocs/index.html" rel="nofollow">API Reference</a> looks a bit imposing. Is...
3
2009-11-17T07:37:08Z
1,918,798
<p>My suggestion is to try to implement some small program and start experimenting with some features starting from the one that are kind of simple. In this way you build momentum and will adventure in the deepest part of it. Of course reading the code of the api itself will help A LOT, and is python so ... a pleasant ...
1
2009-12-17T00:43:16Z
[ "python", "google-app-engine", "google-wave" ]
Google Wave Python Tutorial - What next?
1,747,198
<p>I just finished working through Google's <a href="http://code.google.com/apis/wave/extensions/robots/python-tutorial.html" rel="nofollow">Wave Robot: Python Tutorial</a>. The <a href="http://wave-robot-python-client.googlecode.com/svn/trunk/pydocs/index.html" rel="nofollow">API Reference</a> looks a bit imposing. Is...
3
2009-11-17T07:37:08Z
1,923,119
<p>Have a look at the Python sample bots on the sample gallery : <a href="http://wave-samples-gallery.appspot.com/results?language=Python&amp;api=Robots" rel="nofollow">http://wave-samples-gallery.appspot.com/results?language=Python&amp;api=Robots</a>. This can give you ideas of bots to make, and show you good practice...
3
2009-12-17T16:56:45Z
[ "python", "google-app-engine", "google-wave" ]
How to define the help of the CLI program in the __doc__?
1,747,261
<p>I would like to do something like this :</p> <pre><code>def main(): """ Display Information about a Google Calendar -u --user login Google Login -p --pass password Google Password -d --debug Set DEBUG = True -h --help Display this help """ print(__doc__)...
0
2009-11-17T07:58:09Z
1,747,269
<p>Because <code>__doc__</code> is an <em>attribute of the function</em>, not a local variable. You need to refer to it as <code>main.__doc__</code> like this:</p> <pre><code>def main(): """Display Information about a Google Calendar ...""" print(main.__doc__) if __name__ == "__main__": main() </code...
4
2009-11-17T08:00:29Z
[ "python", "documentation-generation", "command-line-interface" ]
How to define the help of the CLI program in the __doc__?
1,747,261
<p>I would like to do something like this :</p> <pre><code>def main(): """ Display Information about a Google Calendar -u --user login Google Login -p --pass password Google Password -d --debug Set DEBUG = True -h --help Display this help """ print(__doc__)...
0
2009-11-17T07:58:09Z
1,747,471
<p>If the help that you want to print is "global", you might find it more logical to put it as the main documentation for your program:</p> <pre><code>#!/usr/bin/env python """ Display Information about a Google Calendar ... """ if __name__ == '__main__': print __doc__ </code></pre> <p><code>__doc__</code> is a ...
2
2009-11-17T09:00:45Z
[ "python", "documentation-generation", "command-line-interface" ]
Is there a speed difference between WSGI and FCGI?
1,747,266
<p>From the web I've gleaned that WSGI is a CGI for python web development/frameworks. FCGI seems to be a more generalised gateway for a variety of languages. Don't know the performance difference between the two in reference to the languages python and C/++.</p>
25
2009-11-17T07:59:18Z
1,747,336
<p>They are two different things. WSGI is a Python specific interface for writing web applications. There are wrappers for about any web server protocol to provide the WSGI interface. FastGCI (FCGI) is one of such web server protocols. So, WSGI is an abstraction layer, while CGI/FastCGI/mod_python are how the actual we...
17
2009-11-17T08:19:44Z
[ "python", "wsgi", "fastcgi" ]
Is there a speed difference between WSGI and FCGI?
1,747,266
<p>From the web I've gleaned that WSGI is a CGI for python web development/frameworks. FCGI seems to be a more generalised gateway for a variety of languages. Don't know the performance difference between the two in reference to the languages python and C/++.</p>
25
2009-11-17T07:59:18Z
1,748,161
<p>Correct, WSGI is a Python programmatic API definition and FASTCGI is a language agnostic socket wire protocol definition. Effectively they are at different layers with WSGI being a higher layer. In other words, one can implement WSGI on top of something that so happened to use FASTCGI to communicate with a web serve...
60
2009-11-17T11:14:56Z
[ "python", "wsgi", "fastcgi" ]
How to use doctest on a Client script?
1,747,371
<p>I am playing with Google Calendar API, creating some useful function.</p> <p>I another hand, I want to do it right puting some useful doctest and starting agile development.</p> <ul> <li><p><strong>How to write doctest since the result of each function is not really predictible (Depending of what is new on the ser...
0
2009-11-17T08:31:31Z
1,747,414
<p>If you do decide to test an external service, you can use a test fixture:</p> <ul> <li>Write a <code>make_test_server()</code> function, which will return a new server connection to simplify your tests.</li> <li>Make it a test fixture (dummy of the server) <code>make_dummy_test_server()</code> with predictable outp...
1
2009-11-17T08:44:30Z
[ "python", "google-api", "password-protection", "doctest" ]
How make Qt Designers autosize layouts work with Pyqt4?
1,747,475
<p>I'm trying a simple example with Qt Designer and Pyqt4, when I preview the UI in Qt Designer (control+R) it looks good, but when I try to execute the generated UI code, layouts don't work properly and instead of autosizing widgets to the max they are so small that they can't be used.</p> <p>If I use fixed sizes it ...
0
2009-11-17T09:01:43Z
1,748,830
<p>This is a long shot, but isn't the code using QMainWindow and the XML ui-descripting defines a QWidget. I'm not sure if that is the problem, but it does not look 100% correct to me.</p>
0
2009-11-17T13:22:12Z
[ "python", "qt", "pyqt", "designer", "pyqt4" ]
Getting data from an Excel sheet
1,747,501
<p>How do I load data from an Excel sheet into my Django application? I'm using database PosgreSQL as the database.</p> <p>I want to do this programmatically. A client wants to load two different lists onto the website weekly and they don't want to do it in the admin section, they just want the lists loaded from an Ex...
3
2009-11-17T09:07:52Z
1,747,528
<p>Programatically or manually? If manualy then just save the excel as a CSV (with csv or txt extension) and import into Postgresql using</p> <pre><code>copy the_data from '/path/to/csv/MYFILE.txt' DELIMITERS ',' CSV; </code></pre>
0
2009-11-17T09:13:43Z
[ "python", "django", "excel", "postgresql" ]
Getting data from an Excel sheet
1,747,501
<p>How do I load data from an Excel sheet into my Django application? I'm using database PosgreSQL as the database.</p> <p>I want to do this programmatically. A client wants to load two different lists onto the website weekly and they don't want to do it in the admin section, they just want the lists loaded from an Ex...
3
2009-11-17T09:07:52Z
1,747,558
<p>As I remember of this. The best way is to save this sheet as plain text ( CSV or something ) And then load with some custom SQL script. <a href="http://www.postgresql.org/docs/8.3/static/populate.html" rel="nofollow">http://www.postgresql.org/docs/8.3/static/populate.html</a></p>
0
2009-11-17T09:20:51Z
[ "python", "django", "excel", "postgresql" ]
Getting data from an Excel sheet
1,747,501
<p>How do I load data from an Excel sheet into my Django application? I'm using database PosgreSQL as the database.</p> <p>I want to do this programmatically. A client wants to load two different lists onto the website weekly and they don't want to do it in the admin section, they just want the lists loaded from an Ex...
3
2009-11-17T09:07:52Z
1,747,560
<p>Have a look at the <a href="http://pypi.python.org/pypi/xlrd/0.7.1" rel="nofollow">xlrd</a> package, which allows you to read Excel files in Python. Once you've read the data you can do whatever you want with it, including saving it to the database.</p> <p>For a basic usage example, look at <a href="http://science...
6
2009-11-17T09:20:57Z
[ "python", "django", "excel", "postgresql" ]
Getting data from an Excel sheet
1,747,501
<p>How do I load data from an Excel sheet into my Django application? I'm using database PosgreSQL as the database.</p> <p>I want to do this programmatically. A client wants to load two different lists onto the website weekly and they don't want to do it in the admin section, they just want the lists loaded from an Ex...
3
2009-11-17T09:07:52Z
1,747,933
<p>Or have a look at SQLAlchemy if you're going to write some kind of script to help you with that.(<a href="http://www.sqlalchemy.org/" rel="nofollow">http://www.sqlalchemy.org/</a>)</p>
0
2009-11-17T10:32:02Z
[ "python", "django", "excel", "postgresql" ]
Getting data from an Excel sheet
1,747,501
<p>How do I load data from an Excel sheet into my Django application? I'm using database PosgreSQL as the database.</p> <p>I want to do this programmatically. A client wants to load two different lists onto the website weekly and they don't want to do it in the admin section, they just want the lists loaded from an Ex...
3
2009-11-17T09:07:52Z
1,747,995
<p>If you want to use COM to interface excel (i.e. you are running on a Windows machine), see "Migrating Excel data to SQLite" - <a href="http://www.saltycrane.com/blog/2007/11/migrating-excel-to-sqlite-using-python/" rel="nofollow">http://www.saltycrane.com/blog/2007/11/migrating-excel-to-sqlite-using-python/</a></p>
0
2009-11-17T10:44:05Z
[ "python", "django", "excel", "postgresql" ]
Getting data from an Excel sheet
1,747,501
<p>How do I load data from an Excel sheet into my Django application? I'm using database PosgreSQL as the database.</p> <p>I want to do this programmatically. A client wants to load two different lists onto the website weekly and they don't want to do it in the admin section, they just want the lists loaded from an Ex...
3
2009-11-17T09:07:52Z
1,748,726
<p>Have a look at the presentation "Excel &amp; Python" that Chris Withers gave at PyCon US:</p> <p>"This lightning talk explains that you don't need to use COM or be on Windows to read and write native Excel files."</p> <p><a href="http://www.simplistix.co.uk/presentations/python%5Fexcel%5F09/excel-lightning.pdf" re...
2
2009-11-17T13:02:51Z
[ "python", "django", "excel", "postgresql" ]
Getting data from an Excel sheet
1,747,501
<p>How do I load data from an Excel sheet into my Django application? I'm using database PosgreSQL as the database.</p> <p>I want to do this programmatically. A client wants to load two different lists onto the website weekly and they don't want to do it in the admin section, they just want the lists loaded from an Ex...
3
2009-11-17T09:07:52Z
1,748,978
<p>Use django-batchimport <a href="http://code.google.com/p/django-batchimport/" rel="nofollow">http://code.google.com/p/django-batchimport/</a> It provides a very simple way to upload data in Excel sheets to your Django models. I have used it in a couple of projects. It can be integrated very easily into your existing...
3
2009-11-17T13:43:10Z
[ "python", "django", "excel", "postgresql" ]
Getting data from an Excel sheet
1,747,501
<p>How do I load data from an Excel sheet into my Django application? I'm using database PosgreSQL as the database.</p> <p>I want to do this programmatically. A client wants to load two different lists onto the website weekly and they don't want to do it in the admin section, they just want the lists loaded from an Ex...
3
2009-11-17T09:07:52Z
1,843,378
<p>I built django-batchimport on top of xlrd which is AMAZING. The only issues I had were with getting data into Django. Had nothing to do with any limitations of xlrd. It rocks. John's work is incredible.</p> <p>Note that I've actually done some update work to django-batchimport and just released. Take a look: <a hre...
0
2009-12-03T22:20:07Z
[ "python", "django", "excel", "postgresql" ]
Getting data from an Excel sheet
1,747,501
<p>How do I load data from an Excel sheet into my Django application? I'm using database PosgreSQL as the database.</p> <p>I want to do this programmatically. A client wants to load two different lists onto the website weekly and they don't want to do it in the admin section, they just want the lists loaded from an Ex...
3
2009-11-17T09:07:52Z
11,293,612
<p>Just started using XLRD and it looks very easy and simple to use.</p> <p>Beware that it does not support Excel 2007 yet, so keep in mind to save your excel at 2003 format.</p>
-1
2012-07-02T12:21:59Z
[ "python", "django", "excel", "postgresql" ]
Weird Time Issue in Python
1,747,559
<p>Problem with using times in Python.</p> <p><strong>Terminal > Python</strong></p> <pre><code>&gt;&gt;&gt; calendar.timegm(datetime.datetime.now().utctimetuple()) 1258449380 </code></pre> <p>This time indicates <code>GMT: Tue, 17 Nov 2009 09:16:20 GMT</code></p> <p><strong>Eclipse via Django Server</strong></p> ...
1
2009-11-17T09:20:54Z
1,747,576
<p>Bordering on silly, are these two running on the same machine? If not, are both machines using NTP to synchronise time?</p>
0
2009-11-17T09:24:35Z
[ "python", "django", "eclipse", "datetime" ]
Weird Time Issue in Python
1,747,559
<p>Problem with using times in Python.</p> <p><strong>Terminal > Python</strong></p> <pre><code>&gt;&gt;&gt; calendar.timegm(datetime.datetime.now().utctimetuple()) 1258449380 </code></pre> <p>This time indicates <code>GMT: Tue, 17 Nov 2009 09:16:20 GMT</code></p> <p><strong>Eclipse via Django Server</strong></p> ...
1
2009-11-17T09:20:54Z
1,747,580
<p>You can check if it's the same version of python by running <code>python -c "import sys; print sys.path</code> and inspecting the output to see if they are the same.</p> <p>Otherwise - it might be related to your TZ environment variable, or other timezone setting. Perhaps Django sets a global timezone somewhere in ...
2
2009-11-17T09:25:07Z
[ "python", "django", "eclipse", "datetime" ]
Weird Time Issue in Python
1,747,559
<p>Problem with using times in Python.</p> <p><strong>Terminal > Python</strong></p> <pre><code>&gt;&gt;&gt; calendar.timegm(datetime.datetime.now().utctimetuple()) 1258449380 </code></pre> <p>This time indicates <code>GMT: Tue, 17 Nov 2009 09:16:20 GMT</code></p> <p><strong>Eclipse via Django Server</strong></p> ...
1
2009-11-17T09:20:54Z
1,747,597
<p>Django is set to Chicago time. You to change it, edit (or add in) TIME_ZONE flag in settings.py.</p> <p>If you are running on Windows, then Django might mess things up if you don't set it to your local zone - <a href="http://docs.djangoproject.com/en/dev/ref/settings/" rel="nofollow">http://docs.djangoproject.com/e...
7
2009-11-17T09:28:02Z
[ "python", "django", "eclipse", "datetime" ]
Google Wave - Adding a participant to a Wave with the Python API
1,747,685
<p>How do I add a participant to a Wave using the Python API given their email address?</p>
0
2009-11-17T09:46:19Z
1,747,731
<p>The method to add a participant given a user id (AddParticipant) to waves is in the <a href="http://wave-robot-python-client.googlecode.com/svn/trunk/pydocs/index.html" rel="nofollow">waveapi.model.OpBasedWavelet subclass</a>, rather than just waveapi.model.Wavelet. This user id is an email address. Look at <a href=...
0
2009-11-17T09:54:03Z
[ "python", "google-wave" ]
More efficient method for this calculation?
1,747,713
<pre><code>a = 218500000000 s = 6 f = 2 k = 49 d = k + f + s r = a i = 0 while (r &gt;= d): r = r - d #print ('r = ',r) i = i+1 #print ('i = ',i) print (i) </code></pre> <p>I think it does what I expect it to, but its way too slow to calculate such a large number, I waited 5 mins for i to print (while pyth...
0
2009-11-17T09:51:13Z
1,747,728
<p>Isn't a division what you're looking for?</p>
2
2009-11-17T09:53:28Z
[ "python", "iteration", "long-integer", "largenumber" ]
More efficient method for this calculation?
1,747,713
<pre><code>a = 218500000000 s = 6 f = 2 k = 49 d = k + f + s r = a i = 0 while (r &gt;= d): r = r - d #print ('r = ',r) i = i+1 #print ('i = ',i) print (i) </code></pre> <p>I think it does what I expect it to, but its way too slow to calculate such a large number, I waited 5 mins for i to print (while pyth...
0
2009-11-17T09:51:13Z
1,747,747
<p>You can use <code>i = a/d</code>. :D</p>
4
2009-11-17T09:55:41Z
[ "python", "iteration", "long-integer", "largenumber" ]
More efficient method for this calculation?
1,747,713
<pre><code>a = 218500000000 s = 6 f = 2 k = 49 d = k + f + s r = a i = 0 while (r &gt;= d): r = r - d #print ('r = ',r) i = i+1 #print ('i = ',i) print (i) </code></pre> <p>I think it does what I expect it to, but its way too slow to calculate such a large number, I waited 5 mins for i to print (while pyth...
0
2009-11-17T09:51:13Z
1,747,754
<p>try <code>3833333333.3333333333333333333333</code>. AKA <code>r / d</code>.</p>
0
2009-11-17T09:56:35Z
[ "python", "iteration", "long-integer", "largenumber" ]
More efficient method for this calculation?
1,747,713
<pre><code>a = 218500000000 s = 6 f = 2 k = 49 d = k + f + s r = a i = 0 while (r &gt;= d): r = r - d #print ('r = ',r) i = i+1 #print ('i = ',i) print (i) </code></pre> <p>I think it does what I expect it to, but its way too slow to calculate such a large number, I waited 5 mins for i to print (while pyth...
0
2009-11-17T09:51:13Z
1,747,760
<pre><code>r = (a % d) i = (a / d) </code></pre> <p>Use the <a href="http://docs.python.org/reference/expressions.html#binary-arithmetic-operations" rel="nofollow">modulo and division operators</a>.</p> <p>There is also a divmod function to calculate both together:</p> <pre><code>i, r = divmod(a,d) </code></pre>
4
2009-11-17T09:57:19Z
[ "python", "iteration", "long-integer", "largenumber" ]
More efficient method for this calculation?
1,747,713
<pre><code>a = 218500000000 s = 6 f = 2 k = 49 d = k + f + s r = a i = 0 while (r &gt;= d): r = r - d #print ('r = ',r) i = i+1 #print ('i = ',i) print (i) </code></pre> <p>I think it does what I expect it to, but its way too slow to calculate such a large number, I waited 5 mins for i to print (while pyth...
0
2009-11-17T09:51:13Z
1,747,786
<p>Looks like you are doing truncating division to me. That is, you want to find out how many times d goes into a without knowing the remainder.</p> <pre><code>a = 218500000000 s = 6 f = 2 k = 49 d = k + f + s i = a // d print (i) </code></pre>
0
2009-11-17T10:01:57Z
[ "python", "iteration", "long-integer", "largenumber" ]
Integration Testing for a Web App
1,747,772
<p>I want to do full integration testing for a web application. I want to test many things like AJAX, positioning and presence of certain phrases and HTML elements <strong>using several browsers</strong>. I'm seeking a tool to do such automated testing.</p> <p>On the other hand; this is my first time using integration...
8
2009-11-17T09:59:30Z
1,747,804
<p>If you need to do full testing including exploiting browser features like AJAX then I would recomend <a href="http://seleniumhq.org/">Selenium</a>. Selenium launches a browser and controls it to run the tests.</p> <p>It supports all the major <a href="http://seleniumhq.org/about/platforms.html">platforms and browse...
11
2009-11-17T10:05:47Z
[ "python", "ruby", "perl", "automated-tests", "integration-testing" ]
Integration Testing for a Web App
1,747,772
<p>I want to do full integration testing for a web application. I want to test many things like AJAX, positioning and presence of certain phrases and HTML elements <strong>using several browsers</strong>. I'm seeking a tool to do such automated testing.</p> <p>On the other hand; this is my first time using integration...
8
2009-11-17T09:59:30Z
1,747,828
<p>I would also recommend Selenium. It got a really nice Firefox Plugin, that you can use to create your integration tests.</p>
1
2009-11-17T10:09:45Z
[ "python", "ruby", "perl", "automated-tests", "integration-testing" ]