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
Django Admin "Edit Selection" Action?
1,800,008
<p>I'd like to write a django-admin action (for use when the user selects zero or more rows) that will allow them to edit the selected items as a group. I only need to edit one of the items in the model (the "room") at a time, but I don't want to have to go through all 480 of my objects and manually edit them one-by-on...
2
2009-11-25T21:17:15Z
14,406,630
<p>This code adds a django-admin action to do what you want <a href="http://code.google.com/p/django-mass-edit/" rel="nofollow">http://code.google.com/p/django-mass-edit/</a></p>
0
2013-01-18T19:54:31Z
[ "python", "django", "django-admin" ]
replace values in an array
1,800,187
<p>as a replacement value for another within an operation with arrays, or how to search within an array and replace a value by another</p> <p>for example:</p> <pre><code>array ([[NaN, 1., 1., 1., 1., 1., 1.] [1., NaN, 1., 1., 1., 1., 1.] [1., 1., NaN, 1., 1., 1., 1.] [1., 1., 1., NaN, 1., 1., 1.]...
12
2009-11-25T21:46:50Z
1,800,214
<p>You could do this:</p> <pre><code>import numpy as np x=np.array([[np.NaN, 1., 1., 1., 1., 1., 1.],[1., np.NaN, 1., 1., 1., 1., 1.],[1., 1., np.NaN, 1., 1., 1., 1.], [1., 1., 1., np.NaN, 1., 1., 1.], [1., 1., 1., 1., np.NaN, 1., 1.],[1., 1., 1., 1., 1., np.NaN, 1.], [1., 1., 1., 1., 1., 1., np.NaN]]) x[np.isnan(x)]=...
26
2009-11-25T21:53:53Z
[ "python", "numpy" ]
replace values in an array
1,800,187
<p>as a replacement value for another within an operation with arrays, or how to search within an array and replace a value by another</p> <p>for example:</p> <pre><code>array ([[NaN, 1., 1., 1., 1., 1., 1.] [1., NaN, 1., 1., 1., 1., 1.] [1., 1., NaN, 1., 1., 1., 1.] [1., 1., 1., NaN, 1., 1., 1.]...
12
2009-11-25T21:46:50Z
7,796,623
<p>these days there is the special function: </p> <pre><code>a = numpy.nan_to_num(a) </code></pre>
14
2011-10-17T16:21:49Z
[ "python", "numpy" ]
Selenium - Pop Up window
1,800,291
<p>I am testing the Router UI using selenium. I am using cisco routers. I am pinging a website and the router opens a pop up window showing the Ping statistics. The selenium ide is recording the popup window as " Ping table " but when i am running it the ide shows an error.</p> <p>I want to verify and validate the dat...
0
2009-11-25T22:11:30Z
1,800,520
<p>I'd need to reproduce this locally to be able to answer definitively. The only thing that comes to mind right now is that you say the IDE identifies it as "Ping table" but in your python you refer to it as "PingTable". It might be a typo on your behalf, but maybe not.</p>
0
2009-11-25T22:53:58Z
[ "python", "selenium", "popup", "window" ]
Most pythonic way of ignoring output
1,800,396
<p>I've got a class which uses the context management protocol to have a silent stderr stream for a while (mainly used for py2exe deployments, where the app writing anything to stderr causes ugly dialogs when the app is closed, and I'm doing something that I know will have some stderr output)</p> <pre><code>import sys...
2
2009-11-25T22:34:48Z
1,800,424
<p>I feel that the nullWriter class would be more "Pythonic" because it uses the Python interfaces already in place (that you can assign sys.stderr to anything that has a write method), rather than having to go out to the system environment and write to the "bit bucket" as you put it :)</p>
3
2009-11-25T22:40:04Z
[ "python" ]
Most pythonic way of ignoring output
1,800,396
<p>I've got a class which uses the context management protocol to have a silent stderr stream for a while (mainly used for py2exe deployments, where the app writing anything to stderr causes ugly dialogs when the app is closed, and I'm doing something that I know will have some stderr output)</p> <pre><code>import sys...
2
2009-11-25T22:34:48Z
1,800,430
<p>I think the latter solution is the more elegant. You avoid going to the system environment, potentially wasting an fd. Why go out the operating system when it's not needed?</p>
4
2009-11-25T22:41:50Z
[ "python" ]
Most pythonic way of ignoring output
1,800,396
<p>I've got a class which uses the context management protocol to have a silent stderr stream for a while (mainly used for py2exe deployments, where the app writing anything to stderr causes ugly dialogs when the app is closed, and I'm doing something that I know will have some stderr output)</p> <pre><code>import sys...
2
2009-11-25T22:34:48Z
1,800,435
<p>It's a decision between using things that already exist (<code>os.devnull</code>) but are a bit "messier" (you need to <code>open()</code> it etc'), and creating your own solution, which might be simpler, but it's a new class that you're creating.</p> <p>Though both are totally fine, I would have gone with the <cod...
2
2009-11-25T22:42:52Z
[ "python" ]
Most pythonic way of ignoring output
1,800,396
<p>I've got a class which uses the context management protocol to have a silent stderr stream for a while (mainly used for py2exe deployments, where the app writing anything to stderr causes ugly dialogs when the app is closed, and I'm doing something that I know will have some stderr output)</p> <pre><code>import sys...
2
2009-11-25T22:34:48Z
1,800,722
<p>What's wrong with that?</p> <pre><code>import sys sys.stderr = open('/dev/null', 'w') </code></pre>
1
2009-11-25T23:43:10Z
[ "python" ]
Most pythonic way of ignoring output
1,800,396
<p>I've got a class which uses the context management protocol to have a silent stderr stream for a while (mainly used for py2exe deployments, where the app writing anything to stderr causes ugly dialogs when the app is closed, and I'm doing something that I know will have some stderr output)</p> <pre><code>import sys...
2
2009-11-25T22:34:48Z
1,800,833
<p>Thanks all for the replies.</p> <p>I think I will go with the nullWriter approach. I'm aware that both options work, but more interested to see what seems cleaner (esp as the overhead of opening the file is negligable).</p>
0
2009-11-26T00:09:45Z
[ "python" ]
How to intercept WM_DELETE_WINDOW on OSX using Tkinter
1,800,452
<p>I'm trying to keep a Toplevel window from being closed in OSX by intercepting window manager WM_DELETE_WINDOW event. </p> <pre><code>#!/usr/bin/env python from Tkinter import * def speak(): print "woof" root = Tk() root.title("root") win = Toplevel() win.title("win") win.protocol('WM_DELETE_WINDOW', speak) ...
0
2009-11-25T22:45:04Z
6,740,094
<p>See the reply to <a href="http://bugs.python.org/issue12584" rel="nofollow">Python Issue 12584</a>. It appears to be a bug in the very buggy Cocoa Tcl/Tk 8.5 that Apple shipped with OS X 10.6. Don't use it or the Apple-supplied Pythons in 10.6 if you are using Tkinter or anything that uses Tkinter, like IDLE. Mor...
1
2011-07-18T22:16:10Z
[ "python", "osx", "osx-snow-leopard", "tkinter" ]
Genshi table loop
1,800,508
<p>What is wrong with this Genshi template:</p> <pre><code>&lt;html xmlns:py="http://genshi.edgewall.org/"&gt; &lt;head&gt; &lt;title py:content="title"&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;left&gt; &lt;table py: for="i in range(1, len(ctabl))"&gt; &lt;li py: for="e in ctab...
0
2009-11-25T22:51:19Z
1,800,542
<p>I've never used Genshi, but their <a href="http://turbogears.org/2.0/docs/main/Genshi.html#available-processing-directives" rel="nofollow">list of allowed processing directives</a> do not have any spaces between <code>py</code>, the <code>:</code>, and the <code>for</code>. Try removing that space. And anyway, Lin...
1
2009-11-25T23:00:03Z
[ "python", "table", "genshi" ]
Import Multiple CSV files into MySQL with Python
1,800,602
<p>I am trying to use examples that are fun/interesting to me in order to learn MySQL and Python. I am new to both, as I am a finance guy by trade. I have learned quite a bit along the way, but I am at a point where I am not sure where to go.</p> <p>The data files I am looking to import are contained in a zip file, ...
1
2009-11-25T23:14:14Z
1,800,637
<p>Why not use MySQLs own CSV import functionality?</p> <p><a href="http://dev.mysql.com/doc/refman/5.0/en/load-data.html">http://dev.mysql.com/doc/refman/5.0/en/load-data.html</a></p> <pre><code>LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED B...
5
2009-11-25T23:22:10Z
[ "python", "mysql" ]
Import Multiple CSV files into MySQL with Python
1,800,602
<p>I am trying to use examples that are fun/interesting to me in order to learn MySQL and Python. I am new to both, as I am a finance guy by trade. I have learned quite a bit along the way, but I am at a point where I am not sure where to go.</p> <p>The data files I am looking to import are contained in a zip file, ...
1
2009-11-25T23:14:14Z
1,802,246
<p>You'll want to output the actual error, like this:</p> <pre><code>try: cursor.execute(sql) db.commit() except StandardError, e: print e db.rollback() </code></pre> <p>For example, when I execute the above, I get following output</p> <pre><code>(29, "File '/opt/mysql/data/51/test/data.csv' not foun...
1
2009-11-26T08:18:39Z
[ "python", "mysql" ]
Import Multiple CSV files into MySQL with Python
1,800,602
<p>I am trying to use examples that are fun/interesting to me in order to learn MySQL and Python. I am new to both, as I am a finance guy by trade. I have learned quite a bit along the way, but I am at a point where I am not sure where to go.</p> <p>The data files I am looking to import are contained in a zip file, ...
1
2009-11-25T23:14:14Z
14,840,956
<p>I guess you have an error similar to what I had.</p> <p>try </p> <pre><code>LOAD DATA LOCAL INFILE 'data.txt' INTO TABLE tbl_name FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'; </code></pre> <p>instead of </p> <pre><code>LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name FIELDS...
0
2013-02-12T20:12:29Z
[ "python", "mysql" ]
Munging non-printable characters to dots using string.translate()
1,800,790
<p>So I've done this before and it's a surprising ugly bit of code for such a seemingly simple task.</p> <p>The goal is to translate any non-printable character into a <strong>.</strong> (dot). For my purposes "printable" does exclude the last few characters from <code>string.printable</code> (new-lines, tabs, and so...
2
2009-11-25T23:59:30Z
1,800,879
<p>for actual code-golf, I imagine you'd avoid string.maketrans entirely</p> <pre><code>s=set(string.printable[:-5]) newstring = ''.join(x for x in oldstring if x in s else '.') </code></pre> <p>or</p> <pre><code>newstring=re.sub('[^'+string.printable[:-5]+']','',oldstring) </code></pre>
1
2009-11-26T00:19:01Z
[ "python", "code-golf" ]
Munging non-printable characters to dots using string.translate()
1,800,790
<p>So I've done this before and it's a surprising ugly bit of code for such a seemingly simple task.</p> <p>The goal is to translate any non-printable character into a <strong>.</strong> (dot). For my purposes "printable" does exclude the last few characters from <code>string.printable</code> (new-lines, tabs, and so...
2
2009-11-25T23:59:30Z
1,800,882
<p>I don't find this solution ugly. It is certainly more efficient than any regex based solution. Here is a tiny bit shorter solution. But only works in python2.6:</p> <pre><code>nonprintable = string.maketrans('','').translate(None, string.printable[:-5]) filter = string.maketrans(nonprintable, '.' * len(nonprintable...
1
2009-11-26T00:19:21Z
[ "python", "code-golf" ]
Munging non-printable characters to dots using string.translate()
1,800,790
<p>So I've done this before and it's a surprising ugly bit of code for such a seemingly simple task.</p> <p>The goal is to translate any non-printable character into a <strong>.</strong> (dot). For my purposes "printable" does exclude the last few characters from <code>string.printable</code> (new-lines, tabs, and so...
2
2009-11-25T23:59:30Z
1,800,887
<p>Broadest use of "ascii" here, but you get the idea</p> <pre><code>&gt;&gt;&gt; import string &gt;&gt;&gt; ascii="".join(map(chr,range(256))) &gt;&gt;&gt; filter="".join(('.',x)[x in string.printable[:-5]] for x in ascii) &gt;&gt;&gt; ascii.translate(filter) '................................ !"#$%&amp;\'()*+,-./0123...
4
2009-11-26T00:19:56Z
[ "python", "code-golf" ]
Munging non-printable characters to dots using string.translate()
1,800,790
<p>So I've done this before and it's a surprising ugly bit of code for such a seemingly simple task.</p> <p>The goal is to translate any non-printable character into a <strong>.</strong> (dot). For my purposes "printable" does exclude the last few characters from <code>string.printable</code> (new-lines, tabs, and so...
2
2009-11-25T23:59:30Z
1,800,889
<p>Here's another approach using a list comprehension:</p> <pre><code>filter = ''.join([['.', chr(x)][chr(x) in string.printable[:-5]] for x in xrange(256)]) </code></pre>
5
2009-11-26T00:20:08Z
[ "python", "code-golf" ]
How can I get part of regex match as a variable in python?
1,800,817
<p>In Perl it is possible to do something like this (I hope the syntax is right...):</p> <pre><code>$string =~ m/lalala(I want this part)lalala/; $whatIWant = $1; </code></pre> <p>I want to do the same in Python and get the text inside the parenthesis in a string like $1.</p>
7
2009-11-26T00:07:14Z
1,800,850
<pre><code>import re data = "some input data" m = re.search("some (input) data", data) if m: # "if match was successful" / "if matched" print m.group(1) </code></pre> <p>Check the <a href="http://docs.python.org/library/re.html" rel="nofollow">docs</a> for more.</p>
2
2009-11-26T00:12:47Z
[ "python", "regex", "perl" ]
How can I get part of regex match as a variable in python?
1,800,817
<p>In Perl it is possible to do something like this (I hope the syntax is right...):</p> <pre><code>$string =~ m/lalala(I want this part)lalala/; $whatIWant = $1; </code></pre> <p>I want to do the same in Python and get the text inside the parenthesis in a string like $1.</p>
7
2009-11-26T00:07:14Z
1,800,851
<pre><code>import re match = re.match('lalala(I want this part)lalala', 'lalalaI want this partlalala') print match.group(1) </code></pre>
1
2009-11-26T00:12:55Z
[ "python", "regex", "perl" ]
How can I get part of regex match as a variable in python?
1,800,817
<p>In Perl it is possible to do something like this (I hope the syntax is right...):</p> <pre><code>$string =~ m/lalala(I want this part)lalala/; $whatIWant = $1; </code></pre> <p>I want to do the same in Python and get the text inside the parenthesis in a string like $1.</p>
7
2009-11-26T00:07:14Z
1,800,858
<p>See: <a href="https://docs.python.org/2/library/re.html#match-objects" rel="nofollow">Python regex match objects</a></p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; p = re.compile("lalala(I want this part)lalala") &gt;&gt;&gt; p.match("lalalaI want this partlalala").group(1) 'I want this part' </code></pre>
13
2009-11-26T00:13:48Z
[ "python", "regex", "perl" ]
How can I get part of regex match as a variable in python?
1,800,817
<p>In Perl it is possible to do something like this (I hope the syntax is right...):</p> <pre><code>$string =~ m/lalala(I want this part)lalala/; $whatIWant = $1; </code></pre> <p>I want to do the same in Python and get the text inside the parenthesis in a string like $1.</p>
7
2009-11-26T00:07:14Z
1,800,862
<pre><code>import re astr = 'lalalabeeplalala' match = re.search('lalala(.*)lalala', astr) whatIWant = match.group(1) if match else None print(whatIWant) </code></pre> <p>A small note: in Perl, when you write </p> <pre><code>$string =~ m/lalala(.*)lalala/; </code></pre> <p>the regexp can match anywhere in the string...
7
2009-11-26T00:14:59Z
[ "python", "regex", "perl" ]
How can I get part of regex match as a variable in python?
1,800,817
<p>In Perl it is possible to do something like this (I hope the syntax is right...):</p> <pre><code>$string =~ m/lalala(I want this part)lalala/; $whatIWant = $1; </code></pre> <p>I want to do the same in Python and get the text inside the parenthesis in a string like $1.</p>
7
2009-11-26T00:07:14Z
1,800,907
<p>If you want to get parts by name you can also do this:</p> <pre><code>&gt;&gt;&gt; m = re.match(r"(?P&lt;first_name&gt;\w+) (?P&lt;last_name&gt;\w+)", "Malcom Reynolds") &gt;&gt;&gt; m.groupdict() {'first_name': 'Malcom', 'last_name': 'Reynolds'} </code></pre> <p>The example was taken from the <a href="http://docs...
9
2009-11-26T00:24:18Z
[ "python", "regex", "perl" ]
How can I get part of regex match as a variable in python?
1,800,817
<p>In Perl it is possible to do something like this (I hope the syntax is right...):</p> <pre><code>$string =~ m/lalala(I want this part)lalala/; $whatIWant = $1; </code></pre> <p>I want to do the same in Python and get the text inside the parenthesis in a string like $1.</p>
7
2009-11-26T00:07:14Z
1,801,039
<p>there's no need for regex. think simple.</p> <pre><code>&gt;&gt;&gt; "lalala(I want this part)lalala".split("lalala") ['', '(I want this part)', ''] &gt;&gt;&gt; "lalala(I want this part)lalala".split("lalala")[1] '(I want this part)' &gt;&gt;&gt; </code></pre>
2
2009-11-26T01:12:44Z
[ "python", "regex", "perl" ]
How can I get part of regex match as a variable in python?
1,800,817
<p>In Perl it is possible to do something like this (I hope the syntax is right...):</p> <pre><code>$string =~ m/lalala(I want this part)lalala/; $whatIWant = $1; </code></pre> <p>I want to do the same in Python and get the text inside the parenthesis in a string like $1.</p>
7
2009-11-26T00:07:14Z
31,065,857
<pre><code>import re string_to_check = "other_text...lalalaI want this partlalala...other_text" p = re.compile("lalala(I want this part)lalala") # regex pattern m = p.search(string_to_check) # use p.match if what you want is always at beginning of string if m: print m.group(1) </code></p...
0
2015-06-26T05:52:36Z
[ "python", "regex", "perl" ]
Django Html email adds extra characters to the email body
1,801,008
<p>I'm using Django to send an e-mail which has a text part, and an HTML part. Here's the code:</p> <pre> subject = request.session.get('email_subject', None) from_email = request.session.get('user_email', None) to = request.session.get('user_email', None) bcc = [email.strip() for email in request.sess...
1
2009-11-26T01:00:15Z
1,801,097
<p>You are generating <code>html_content</code> and <code>text_content</code> with <code>render_to_response</code>, which returns an <code>HttpResponse</code> object. </p> <p>However you want <code>html_content</code> and <code>text_content</code> to be strings, so use <a href="http://docs.djangoproject.com/en/dev/ref...
4
2009-11-26T01:32:36Z
[ "python", "django", "email" ]
Django Html email adds extra characters to the email body
1,801,008
<p>I'm using Django to send an e-mail which has a text part, and an HTML part. Here's the code:</p> <pre> subject = request.session.get('email_subject', None) from_email = request.session.get('user_email', None) to = request.session.get('user_email', None) bcc = [email.strip() for email in request.sess...
1
2009-11-26T01:00:15Z
1,801,508
<p>Before you go with Alasdair's suggestion, fire up the shell and take a look at the output from <code>render_to_string</code> and <code>render_to_response</code>. The shell just might help you figure out a problem like this in the future.</p> <p>The "Content-Type: text/html; charset=utf-8" line that you mentioned i...
1
2009-11-26T04:18:10Z
[ "python", "django", "email" ]
How does wsgi handle multiple request headers with the same name?
1,801,124
<p>In WSGI headers are represented in the environ as 'HTTP_XXX' values. For example the value <code>Cookie:</code> header is stored at the <code>HTTP_COOKIE</code> key of the environ.</p> <p>How are multiple request headers with the same header name represented?</p>
10
2009-11-26T01:41:31Z
1,801,177
<p>I thought the answer to this one would be trivial, but after digging a bit I'm not so sure.</p> <p>Here's what I've found so far:</p> <p>The WSGI PEP-333 (<a href="http://www.python.org/dev/peps/pep-0333/" rel="nofollow">http://www.python.org/dev/peps/pep-0333/</a>) suggests that the environment variables should c...
2
2009-11-26T02:02:15Z
[ "python", "http", "wsgi" ]
How does wsgi handle multiple request headers with the same name?
1,801,124
<p>In WSGI headers are represented in the environ as 'HTTP_XXX' values. For example the value <code>Cookie:</code> header is stored at the <code>HTTP_COOKIE</code> key of the environ.</p> <p>How are multiple request headers with the same header name represented?</p>
10
2009-11-26T01:41:31Z
1,801,191
<p>Multiple cookies are combined into a single header, separated by semicolons.</p> <p>Multiple headers are allowed by <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2">the HTTP spec</a>, but only for certain kinds of headers, and it is always permissible to combine those headers into one (though ...
9
2009-11-26T02:09:47Z
[ "python", "http", "wsgi" ]
django template url function not matching in app
1,801,165
<p>I have a django project set up with an app called pub. I'm trying to set it up so that I can include urls.py from each app (there will be more as I go) in the top-level urls.py. I've also got a template that uses the 'url' function to resolve a url on a view, defined in the openidgae module. The problem is that a...
0
2009-11-26T01:55:51Z
1,801,533
<p>I don't understand what the problem is that you're facing, but just by looking at your urls.py files, you should probably change the top level urls.py to something like</p> <pre><code>from django.conf.urls.defaults import * urlpatterns = patterns('', (r'', include('openidgae.urls')), (r'^pub/', include('pub....
1
2009-11-26T04:28:40Z
[ "python", "django", "google-app-engine" ]
django template url function not matching in app
1,801,165
<p>I have a django project set up with an app called pub. I'm trying to set it up so that I can include urls.py from each app (there will be more as I go) in the top-level urls.py. I've also got a template that uses the 'url' function to resolve a url on a view, defined in the openidgae module. The problem is that a...
0
2009-11-26T01:55:51Z
1,806,003
<p>You post a lot of code, but you haven't been very clear about what the actual problem is. First of all having</p> <pre><code>(r'', 'pub.views.index'), (r'^/$', 'pub.views.index'), </code></pre> <p>can give some problems if you want to find the url. What should the url be for <code>pub.views.index</code>? From what...
0
2009-11-26T22:45:34Z
[ "python", "django", "google-app-engine" ]
Is smtplib pure python or implemented in C?
1,801,271
<p>Is smtplib pure python or implemented in C?</p>
5
2009-11-26T02:40:31Z
1,801,277
<p>smtplib itself is implemented in python but socket is based on C, so its means both.</p>
4
2009-11-26T02:43:22Z
[ "python", "c", "smtplib" ]
Is smtplib pure python or implemented in C?
1,801,271
<p>Is smtplib pure python or implemented in C?</p>
5
2009-11-26T02:40:31Z
1,801,281
<p>Basically pure Python (as the underlying implementation if you go down far enough is C). You can find the source under the Lib\ directory in your Python root.</p>
2
2009-11-26T02:44:26Z
[ "python", "c", "smtplib" ]
Is smtplib pure python or implemented in C?
1,801,271
<p>Is smtplib pure python or implemented in C?</p>
5
2009-11-26T02:40:31Z
1,801,282
<pre><code>In [32]: import smtplib In [33]: smtplib Out[33]: &lt;module 'smtplib' from '/usr/lib/python2.6/smtplib.pyc'&gt; </code></pre> <p>Therefore, smtplib is written in python.</p>
8
2009-11-26T02:44:35Z
[ "python", "c", "smtplib" ]
Anyone know where I can download a zipped Python distribution?
1,801,286
<p>Yeah, kind of random, but I was wondering if anyone could link me to a .zip file containing a Python distribution. I know I could download the installer, so please don't suggest that. :P.</p>
0
2009-11-26T02:47:21Z
1,801,314
<p>I didn't exactly understand what you want. Is <a href="http://portablepython.com/" rel="nofollow">Portable Python</a> enough for you? If it isn't, check Python's <a href="http://python.org/download/" rel="nofollow">official download</a> website where you have a lot of options - including compressed source tarballs. ...
3
2009-11-26T02:58:06Z
[ "python", "download" ]
Anyone know where I can download a zipped Python distribution?
1,801,286
<p>Yeah, kind of random, but I was wondering if anyone could link me to a .zip file containing a Python distribution. I know I could download the installer, so please don't suggest that. :P.</p>
0
2009-11-26T02:47:21Z
1,801,327
<p>Can you use the official <a href="http://python.org/ftp/python/3.1.1/Python-3.1.1.tar.bz2" rel="nofollow">Source Distribution</a> of Python? It is not zipped, but you can unpack the whole thing in one line of Python.</p> <pre><code>import tarfile; tarfile.open('Python-3.1.1.tar.bz2').extractall() </code></pre>
2
2009-11-26T03:04:37Z
[ "python", "download" ]
How to deal with rounding errors of floating types for financial calculations in Python SQLite?
1,801,307
<p>I'm creating a financial app and it seems my floats in sqlite are floating around. Sometimes a 4.0 will be a 4.000009, and a 6.0 will be a 6.00006, things like that. How can I make these more exact and not affect my financial calculations?</p> <p>Values are coming from Python if that matters. Not sure which area ...
4
2009-11-26T02:55:34Z
1,801,313
<p>Please use Decimal </p> <p><a href="http://docs.python.org/library/decimal.html" rel="nofollow">http://docs.python.org/library/decimal.html</a></p>
6
2009-11-26T02:58:02Z
[ "python", "sqlite", "floating-point" ]
How to deal with rounding errors of floating types for financial calculations in Python SQLite?
1,801,307
<p>I'm creating a financial app and it seems my floats in sqlite are floating around. Sometimes a 4.0 will be a 4.000009, and a 6.0 will be a 6.00006, things like that. How can I make these more exact and not affect my financial calculations?</p> <p>Values are coming from Python if that matters. Not sure which area ...
4
2009-11-26T02:55:34Z
1,801,319
<p>Seeing as this is a financial application, <em>if</em> you only have calculations up to 2 or 3 decimal places, you can store all the data internally as integers, and only convert them to float for presentation purposes.</p> <p>E.g.</p> <pre><code>6.00 -&gt; 600 4.35 -&gt; 435 </code></pre>
4
2009-11-26T03:00:02Z
[ "python", "sqlite", "floating-point" ]
How to deal with rounding errors of floating types for financial calculations in Python SQLite?
1,801,307
<p>I'm creating a financial app and it seems my floats in sqlite are floating around. Sometimes a 4.0 will be a 4.000009, and a 6.0 will be a 6.00006, things like that. How can I make these more exact and not affect my financial calculations?</p> <p>Values are coming from Python if that matters. Not sure which area ...
4
2009-11-26T02:55:34Z
1,801,366
<p>You have to use decimal numbers. Decimal numbers can be represented exactly. </p> <p>In decimal floating point, <code>0.1 + 0.1 + 0.1 - 0.3</code> is exactly equal to zero. In binary floating point, the result is <code>5.5511151231257827e-017.</code></p> <p>So, just try decimal:</p> <pre><code>import decimal </co...
0
2009-11-26T03:21:06Z
[ "python", "sqlite", "floating-point" ]
How to deal with rounding errors of floating types for financial calculations in Python SQLite?
1,801,307
<p>I'm creating a financial app and it seems my floats in sqlite are floating around. Sometimes a 4.0 will be a 4.000009, and a 6.0 will be a 6.00006, things like that. How can I make these more exact and not affect my financial calculations?</p> <p>Values are coming from Python if that matters. Not sure which area ...
4
2009-11-26T02:55:34Z
1,801,439
<p>This is a common problem using SQLite as it does not have a Currency type.<br> As S.Mark said you can use the <a href="http://docs.python.org/library/decimal.html" rel="nofollow">Decimal</a> representation library. However SQLite 3 only supports binary floating point numbers (sqlite type REAL) so you would have to s...
3
2009-11-26T03:49:57Z
[ "python", "sqlite", "floating-point" ]
How to deal with rounding errors of floating types for financial calculations in Python SQLite?
1,801,307
<p>I'm creating a financial app and it seems my floats in sqlite are floating around. Sometimes a 4.0 will be a 4.000009, and a 6.0 will be a 6.00006, things like that. How can I make these more exact and not affect my financial calculations?</p> <p>Values are coming from Python if that matters. Not sure which area ...
4
2009-11-26T02:55:34Z
1,801,521
<p>Most people would probably use Decimal for this, however if this doesn't map onto a database type you may take a performance hit.</p> <p>If performance is important you might want to consider using Integers to represent an appropriate currency unit - often cents or tenths of cents is ok.</p> <p>There should be bus...
1
2009-11-26T04:24:22Z
[ "python", "sqlite", "floating-point" ]
How to deal with rounding errors of floating types for financial calculations in Python SQLite?
1,801,307
<p>I'm creating a financial app and it seems my floats in sqlite are floating around. Sometimes a 4.0 will be a 4.000009, and a 6.0 will be a 6.00006, things like that. How can I make these more exact and not affect my financial calculations?</p> <p>Values are coming from Python if that matters. Not sure which area ...
4
2009-11-26T02:55:34Z
1,806,172
<p>Use <a href="http://docs.python.org/library/decimal.html" rel="nofollow">Decimal</a> to manipulate your figures, then use <a href="http://docs.python.org/library/pickle.html" rel="nofollow">pickle</a> to save it and load it from SQLite as text, since it doesn't handle numeric types.</p> <p>Finaly, use <a href="http...
1
2009-11-26T23:51:24Z
[ "python", "sqlite", "floating-point" ]
django embedding user id into URL template best practice
1,801,350
<p>I'm building a navigation menu in my django app, and one of the options is "My Account". There are different roles I have for users, but in order for them all to view their profile, I use a generic URL such as <a href="http://mysite/user/" rel="nofollow">http://mysite/user/</a>/profile.</p> <p>What's a Django best ...
4
2009-11-26T03:14:16Z
1,801,372
<p>Your first try matches the url listed in your URLconf. I'd also use that aproach.</p>
-2
2009-11-26T03:23:43Z
[ "python", "django" ]
django embedding user id into URL template best practice
1,801,350
<p>I'm building a navigation menu in my django app, and one of the options is "My Account". There are different roles I have for users, but in order for them all to view their profile, I use a generic URL such as <a href="http://mysite/user/" rel="nofollow">http://mysite/user/</a>/profile.</p> <p>What's a Django best ...
4
2009-11-26T03:14:16Z
1,801,387
<p>Look into named URLs, you can find the official django documentation <a href="http://docs.djangoproject.com/en/dev/topics/http/urls/#url">here</a>.</p> <p>Basically you can name your URLs in your URL conf as such:</p> <pre><code>url(r'^user/(?P&lt;user_id&gt;\d+)/profile/$', 'yourapp.views.view', name='user_url') ...
9
2009-11-26T03:29:53Z
[ "python", "django" ]
django embedding user id into URL template best practice
1,801,350
<p>I'm building a navigation menu in my django app, and one of the options is "My Account". There are different roles I have for users, but in order for them all to view their profile, I use a generic URL such as <a href="http://mysite/user/" rel="nofollow">http://mysite/user/</a>/profile.</p> <p>What's a Django best ...
4
2009-11-26T03:14:16Z
1,802,223
<p>Easiest way - define a <code>get_absolute_url</code> method in your model and use that, in conjunction with the <code>permalink</code> decorator if you like.</p>
2
2009-11-26T08:13:03Z
[ "python", "django" ]
Algorithm - How to delete duplicate elements in a list efficiently?
1,801,459
<p>There is a <strong>list L</strong>. It contains elements of <strong>arbitrary type each</strong>. How to delete all duplicate elements in such list efficiently? <strong>ORDER must be preserved</strong></p> <p>Just an algorithm is required, so no import any external library is allowed.</p> <h3>Related questions</h3...
9
2009-11-26T03:59:32Z
1,801,471
<p>Assuming order matters:</p> <ul> <li>Create an empty set S and an empty list M.</li> <li>Scan the list L one element at a time.</li> <li>If the element is in the set S, skip it.</li> <li>Otherwise, add it to M and to S.</li> <li>Repeat for all elements in L.</li> <li>Return M.</li> </ul> <p>In Python:</p> <pre><c...
27
2009-11-26T04:02:07Z
[ "java", "c++", "python", "algorithm", "haskell" ]
Algorithm - How to delete duplicate elements in a list efficiently?
1,801,459
<p>There is a <strong>list L</strong>. It contains elements of <strong>arbitrary type each</strong>. How to delete all duplicate elements in such list efficiently? <strong>ORDER must be preserved</strong></p> <p>Just an algorithm is required, so no import any external library is allowed.</p> <h3>Related questions</h3...
9
2009-11-26T03:59:32Z
1,801,475
<h2>Special Case: Hashing and Equality</h2> <p>Firstly, we need to determine something about the assumptions, namely the existence of an equals and has function relationship. What do I mean by this? I mean that for the set of source objects S, given any two objects x1 and x2 that are elements of S there exists a (hash...
17
2009-11-26T04:03:21Z
[ "java", "c++", "python", "algorithm", "haskell" ]
Algorithm - How to delete duplicate elements in a list efficiently?
1,801,459
<p>There is a <strong>list L</strong>. It contains elements of <strong>arbitrary type each</strong>. How to delete all duplicate elements in such list efficiently? <strong>ORDER must be preserved</strong></p> <p>Just an algorithm is required, so no import any external library is allowed.</p> <h3>Related questions</h3...
9
2009-11-26T03:59:32Z
1,801,477
<p>If the order does not matter, you might want to try this algorithm written in Python:</p> <pre><code>&gt;&gt;&gt; array = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6] &gt;&gt;&gt; unique = set(array) &gt;&gt;&gt; list(unique) [1, 2, 3, 4, 5, 6] </code></pre>
7
2009-11-26T04:04:21Z
[ "java", "c++", "python", "algorithm", "haskell" ]
Algorithm - How to delete duplicate elements in a list efficiently?
1,801,459
<p>There is a <strong>list L</strong>. It contains elements of <strong>arbitrary type each</strong>. How to delete all duplicate elements in such list efficiently? <strong>ORDER must be preserved</strong></p> <p>Just an algorithm is required, so no import any external library is allowed.</p> <h3>Related questions</h3...
9
2009-11-26T03:59:32Z
1,801,553
<p>In java, it's a one liner.</p> <pre><code>Set set = new LinkedHashSet(list); </code></pre> <p>will give you a collection with duplicate items removed.</p>
3
2009-11-26T04:37:25Z
[ "java", "c++", "python", "algorithm", "haskell" ]
Algorithm - How to delete duplicate elements in a list efficiently?
1,801,459
<p>There is a <strong>list L</strong>. It contains elements of <strong>arbitrary type each</strong>. How to delete all duplicate elements in such list efficiently? <strong>ORDER must be preserved</strong></p> <p>Just an algorithm is required, so no import any external library is allowed.</p> <h3>Related questions</h3...
9
2009-11-26T03:59:32Z
1,801,555
<p>For Java could go with this:</p> <pre><code>private static &lt;T&gt; void removeDuplicates(final List&lt;T&gt; list) { final LinkedHashSet&lt;T&gt; set; set = new LinkedHashSet&lt;T&gt;(list); list.clear(); list.addAll(set); } </code></pre>
2
2009-11-26T04:38:27Z
[ "java", "c++", "python", "algorithm", "haskell" ]
Algorithm - How to delete duplicate elements in a list efficiently?
1,801,459
<p>There is a <strong>list L</strong>. It contains elements of <strong>arbitrary type each</strong>. How to delete all duplicate elements in such list efficiently? <strong>ORDER must be preserved</strong></p> <p>Just an algorithm is required, so no import any external library is allowed.</p> <h3>Related questions</h3...
9
2009-11-26T03:59:32Z
1,801,575
<p>in haskell this would be covered by the <code>nub</code> and <code>nubBy</code> functions</p> <pre><code>nub :: Eq a =&gt; [a] -&gt; [a] nub [] = [] nub (x:xs) = x : nub (filter (/= x) xs) nubBy :: (a -&gt; a -&gt; Bool) -&gt; [a] -&gt; [a] nubBy f [] = [] nubBy f (x:xs) = x : nub (filter (not.f x) xs) </code></pr...
7
2009-11-26T04:45:39Z
[ "java", "c++", "python", "algorithm", "haskell" ]
Algorithm - How to delete duplicate elements in a list efficiently?
1,801,459
<p>There is a <strong>list L</strong>. It contains elements of <strong>arbitrary type each</strong>. How to delete all duplicate elements in such list efficiently? <strong>ORDER must be preserved</strong></p> <p>Just an algorithm is required, so no import any external library is allowed.</p> <h3>Related questions</h3...
9
2009-11-26T03:59:32Z
1,801,634
<p>In Python</p> <pre><code>&gt;&gt;&gt; L = [2, 1, 4, 3, 5, 1, 2, 1, 1, 6, 5] &gt;&gt;&gt; a=[] &gt;&gt;&gt; for i in L: ... if not i in a: ... a.append(i) ... &gt;&gt;&gt; print a [2, 1, 4, 3, 5, 6] &gt;&gt;&gt; </code></pre>
2
2009-11-26T05:03:44Z
[ "java", "c++", "python", "algorithm", "haskell" ]
Algorithm - How to delete duplicate elements in a list efficiently?
1,801,459
<p>There is a <strong>list L</strong>. It contains elements of <strong>arbitrary type each</strong>. How to delete all duplicate elements in such list efficiently? <strong>ORDER must be preserved</strong></p> <p>Just an algorithm is required, so no import any external library is allowed.</p> <h3>Related questions</h3...
9
2009-11-26T03:59:32Z
1,801,727
<p><strong>One line solution in Python</strong>.<br> Using lists-comprehesion:</p> <pre><code>&gt;&gt;&gt; L = [2, 1, 4, 3, 5, 1, 2, 1, 1, 6, 5] &gt;&gt;&gt; M = [] &gt;&gt;&gt; zip(*[(e,M.append(e)) for e in L if not e in M])[0] (2, 1, 4, 3, 5, 6) </code></pre>
0
2009-11-26T05:37:12Z
[ "java", "c++", "python", "algorithm", "haskell" ]
Algorithm - How to delete duplicate elements in a list efficiently?
1,801,459
<p>There is a <strong>list L</strong>. It contains elements of <strong>arbitrary type each</strong>. How to delete all duplicate elements in such list efficiently? <strong>ORDER must be preserved</strong></p> <p>Just an algorithm is required, so no import any external library is allowed.</p> <h3>Related questions</h3...
9
2009-11-26T03:59:32Z
1,801,814
<ul> <li>go through the list and assign sequential index to each item</li> <li>sort the list basing on some comparison function for elements</li> <li>remove duplicates</li> <li>sort the list basing on assigned indices</li> </ul> <p>for simplicity indices for items may be stored in something like std::map</p> <p>looks...
1
2009-11-26T06:07:16Z
[ "java", "c++", "python", "algorithm", "haskell" ]
Algorithm - How to delete duplicate elements in a list efficiently?
1,801,459
<p>There is a <strong>list L</strong>. It contains elements of <strong>arbitrary type each</strong>. How to delete all duplicate elements in such list efficiently? <strong>ORDER must be preserved</strong></p> <p>Just an algorithm is required, so no import any external library is allowed.</p> <h3>Related questions</h3...
9
2009-11-26T03:59:32Z
1,802,021
<p>Maybe you should look into using associate arrays (aka dict in python) to avoid having duplicate elements in the first place.</p>
0
2009-11-26T07:13:44Z
[ "java", "c++", "python", "algorithm", "haskell" ]
Algorithm - How to delete duplicate elements in a list efficiently?
1,801,459
<p>There is a <strong>list L</strong>. It contains elements of <strong>arbitrary type each</strong>. How to delete all duplicate elements in such list efficiently? <strong>ORDER must be preserved</strong></p> <p>Just an algorithm is required, so no import any external library is allowed.</p> <h3>Related questions</h3...
9
2009-11-26T03:59:32Z
1,812,795
<p>It depends on what you mean by "efficently". The naive algorithm is O(n^2), and I assume what you actually mean is that you want something of lower order than that.</p> <p>As Maxim100 says, you can preserve the order by pairing the list with a series of numbers, use any algorithm you like, and then resort the rema...
1
2009-11-28T15:29:31Z
[ "java", "c++", "python", "algorithm", "haskell" ]
Algorithm - How to delete duplicate elements in a list efficiently?
1,801,459
<p>There is a <strong>list L</strong>. It contains elements of <strong>arbitrary type each</strong>. How to delete all duplicate elements in such list efficiently? <strong>ORDER must be preserved</strong></p> <p>Just an algorithm is required, so no import any external library is allowed.</p> <h3>Related questions</h3...
9
2009-11-26T03:59:32Z
1,822,857
<h2>Delete duplicates in a list inplace in Python</h2> <h3>Case: Items in the list are not hashable or comparable</h3> <p>That is we can't use <code>set</code> (<code>dict</code>) or <code>sort</code>.</p> <pre><code>from itertools import islice def del_dups2(lst): """O(n**2) algorithm, O(1) in memory""" po...
1
2009-11-30T22:27:36Z
[ "java", "c++", "python", "algorithm", "haskell" ]
Algorithm - How to delete duplicate elements in a list efficiently?
1,801,459
<p>There is a <strong>list L</strong>. It contains elements of <strong>arbitrary type each</strong>. How to delete all duplicate elements in such list efficiently? <strong>ORDER must be preserved</strong></p> <p>Just an algorithm is required, so no import any external library is allowed.</p> <h3>Related questions</h3...
9
2009-11-26T03:59:32Z
13,442,800
<p>I've written an algorithm for string. Actually it does not matter what type do you have.</p> <pre><code>static string removeDuplicates(string str) { if (String.IsNullOrEmpty(str) || str.Length &lt; 2) { return str; } char[] arr = str.ToCharArray(); int len = arr.Length; int pos = 1; ...
1
2012-11-18T17:48:51Z
[ "java", "c++", "python", "algorithm", "haskell" ]
Algorithm - How to delete duplicate elements in a list efficiently?
1,801,459
<p>There is a <strong>list L</strong>. It contains elements of <strong>arbitrary type each</strong>. How to delete all duplicate elements in such list efficiently? <strong>ORDER must be preserved</strong></p> <p>Just an algorithm is required, so no import any external library is allowed.</p> <h3>Related questions</h3...
9
2009-11-26T03:59:32Z
15,595,462
<p>My code in Java:</p> <pre><code>ArrayList&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;(); list.addAll({1,2,1,3,4,5,2,3,4,3}); for (int i=0; i&lt;list.size(); i++) { for (int j=i+1; j&lt;list.size(); j++) { if (list.get(i) == list.get(j)) { list.remove(i); j--;...
0
2013-03-24T05:20:50Z
[ "java", "c++", "python", "algorithm", "haskell" ]
Algorithm - How to delete duplicate elements in a list efficiently?
1,801,459
<p>There is a <strong>list L</strong>. It contains elements of <strong>arbitrary type each</strong>. How to delete all duplicate elements in such list efficiently? <strong>ORDER must be preserved</strong></p> <p>Just an algorithm is required, so no import any external library is allowed.</p> <h3>Related questions</h3...
9
2009-11-26T03:59:32Z
28,763,366
<p>Algorithm delete_duplicates (a[1....n])</p> <p><strong><em>//Remove duplicates from the given array</em></strong></p> <p><strong><em>//input parameters :a[1:n], an array of n elements</em></strong></p> <p>{</p> <p><code>temp[1:n];</code> <em>//an array of n elements</em> </p> <pre><code> temp[i]=a[i];for i=1 to...
0
2015-02-27T10:54:24Z
[ "java", "c++", "python", "algorithm", "haskell" ]
Why does SWIG crash Python when linked to gtkglext?
1,801,518
<p>Anything I link to gtkglext using SWIG crashes Python on exit. Why does this crash?</p> <p>test.i:</p> <pre><code>%module test %{ void test() { printf("Test.\n"); } %} void test(); </code></pre> <p>Session:</p> <pre><code>$ swig -python test.i $ g++ -I/usr/include/python2.6 -shared -fPIC -o _test.so test_wrap....
1
2009-11-26T04:23:54Z
1,802,844
<p>You need to init gtk properly.</p> <pre><code>$ cat test.i %module test %{ void test() { printf("Test.\n"); } %} void test(); $ swig -python test.i ; gcc -I/usr/include/python2.5 -shared -fPIC -o _test.so test_wrap.c -lpython2.5 `pkg-config --libs gtkglext-1.0` $ python -c 'import test; test.test()' Test. Segmenta...
1
2009-11-26T10:24:31Z
[ "python", "scripting", "swig" ]
Convert a Python list with strings all to lowercase or uppercase
1,801,668
<p>I have a python list variable that contains strings. Is there a python function that can convert all the strings in one pass to lowercase and vice versa, uppercase?</p>
85
2009-11-26T05:15:52Z
1,801,676
<p>It can be done with list comprehensions</p> <pre><code>&gt;&gt;&gt; [x.lower() for x in ["A","B","C"]] ['a', 'b', 'c'] &gt;&gt;&gt; [x.upper() for x in ["a","b","c"]] ['A', 'B', 'C'] </code></pre> <p>or with map function</p> <pre><code>&gt;&gt;&gt; map(lambda x:x.lower(),["A","B","C"]) ['a', 'b', 'c'] &gt;&gt;&gt...
165
2009-11-26T05:19:47Z
[ "python", "list" ]
Convert a Python list with strings all to lowercase or uppercase
1,801,668
<p>I have a python list variable that contains strings. Is there a python function that can convert all the strings in one pass to lowercase and vice versa, uppercase?</p>
85
2009-11-26T05:15:52Z
1,801,683
<p>List comprehensions is how I'd do it. This snippet below shows how to convert a list to all upper case then back to lower:</p> <pre><code>$ python Python 2.5.2 (r252:60911, Dec 2 2008, 09:26:14) [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin Type "help", "copyright", "credits" or "license" for ...
7
2009-11-26T05:23:03Z
[ "python", "list" ]
Convert a Python list with strings all to lowercase or uppercase
1,801,668
<p>I have a python list variable that contains strings. Is there a python function that can convert all the strings in one pass to lowercase and vice versa, uppercase?</p>
85
2009-11-26T05:15:52Z
1,801,689
<pre><code>mylist = ['Mixed Case One', 'Mixed Case Two', 'Mixed Three'] print map(lambda x: x.lower(), mylist) print map(lambda x: x.upper(), mylist) </code></pre>
1
2009-11-26T05:24:29Z
[ "python", "list" ]
Convert a Python list with strings all to lowercase or uppercase
1,801,668
<p>I have a python list variable that contains strings. Is there a python function that can convert all the strings in one pass to lowercase and vice versa, uppercase?</p>
85
2009-11-26T05:15:52Z
1,801,690
<pre><code>&gt;&gt;&gt; map(str.lower,["A","B","C"]) ['a', 'b', 'c'] </code></pre>
12
2009-11-26T05:24:40Z
[ "python", "list" ]
Convert a Python list with strings all to lowercase or uppercase
1,801,668
<p>I have a python list variable that contains strings. Is there a python function that can convert all the strings in one pass to lowercase and vice versa, uppercase?</p>
85
2009-11-26T05:15:52Z
1,801,780
<p>Besides being easier to read (for many people), list comprehensions win the speed race, too:</p> <pre><code>$ python2.6 -m timeit '[x.lower() for x in ["A","B","C"]]' 1000000 loops, best of 3: 1.03 usec per loop $ python2.6 -m timeit '[x.upper() for x in ["a","b","c"]]' 1000000 loops, best of 3: 1.04 usec per loop ...
30
2009-11-26T05:54:36Z
[ "python", "list" ]
Convert a Python list with strings all to lowercase or uppercase
1,801,668
<p>I have a python list variable that contains strings. Is there a python function that can convert all the strings in one pass to lowercase and vice versa, uppercase?</p>
85
2009-11-26T05:15:52Z
1,801,789
<p>For this sample the comprehension is fastest</p> <pre> $ python -m timeit -s 's=["one","two","three"]*1000' '[x.upper for x in s]' 1000 loops, best of 3: 809 usec per loop $ python -m timeit -s 's=["one","two","three"]*1000' 'map(str.upper,s)' 1000 loops, best of 3: 1.12 msec per loop $ python -m timeit -s 's=["o...
3
2009-11-26T05:59:13Z
[ "python", "list" ]
Convert a Python list with strings all to lowercase or uppercase
1,801,668
<p>I have a python list variable that contains strings. Is there a python function that can convert all the strings in one pass to lowercase and vice versa, uppercase?</p>
85
2009-11-26T05:15:52Z
33,564,232
<p>a student asking, another student with the same problem answering :))</p> <pre><code>fruits=['orange', 'grape', 'kiwi', 'apple', 'mango', 'fig', 'lemon'] newList = [] for fruit in fruits: newList.append(fruit.upper()) print(newlist) </code></pre>
0
2015-11-06T10:08:10Z
[ "python", "list" ]
Python - Multi-Dimensional Arrays
1,801,819
<p>Python does not provide built-in support for multi-dimensional arrays. I need to develop an <strong>11-dimensional array</strong> and a set of functions to operate on it (mostly linear algebra, vector arithmetics). However, <strong>no external library import is allowed</strong>. I have a code in C and trying to por...
2
2009-11-26T06:08:21Z
1,801,864
<p>I've written a <code>Matrix</code> class here:</p> <p><a href="http://stackoverflow.com/questions/508657/multidimensional-array-in-python/508677#508677">Multidimensional array in Python</a></p> <p>It can be used like this:</p> <pre><code>m = Matrix(4,5,2,6) m[2,3,1,3] = 'x' m[2,3,1,3] // -&gt; 'x' </code></pre>
2
2009-11-26T06:23:13Z
[ "python", "c" ]
Python - Multi-Dimensional Arrays
1,801,819
<p>Python does not provide built-in support for multi-dimensional arrays. I need to develop an <strong>11-dimensional array</strong> and a set of functions to operate on it (mostly linear algebra, vector arithmetics). However, <strong>no external library import is allowed</strong>. I have a code in C and trying to por...
2
2009-11-26T06:08:21Z
1,801,895
<p>With so many dimensions, and no library imports allowed, I'd go (as the basic choice) for a dictionary indexed by tuples. This way, you get very nice syntax for simple indexing:</p> <pre><code>Array = dict() Array[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] = [1.0, 0.0, 0.0] </code></pre> <p>You'll probably want to wrap it ...
6
2009-11-26T06:32:14Z
[ "python", "c" ]
Python - Multi-Dimensional Arrays
1,801,819
<p>Python does not provide built-in support for multi-dimensional arrays. I need to develop an <strong>11-dimensional array</strong> and a set of functions to operate on it (mostly linear algebra, vector arithmetics). However, <strong>no external library import is allowed</strong>. I have a code in C and trying to por...
2
2009-11-26T06:08:21Z
1,801,898
<p>"Multi-dimension" is just a fancy term to mean "many memory locations". If you look at it in a broader sense, they are just really "1 dimensional". Anyway, to suggest an alternative, you can use dictionaries.</p> <pre><code>&gt;&gt;&gt; d={} &gt;&gt;&gt; d[0]={} &gt;&gt;&gt; d[0][0]="1" &gt;&gt;&gt; d[0] {0: '1'} <...
0
2009-11-26T06:33:22Z
[ "python", "c" ]
Python - Multi-Dimensional Arrays
1,801,819
<p>Python does not provide built-in support for multi-dimensional arrays. I need to develop an <strong>11-dimensional array</strong> and a set of functions to operate on it (mostly linear algebra, vector arithmetics). However, <strong>no external library import is allowed</strong>. I have a code in C and trying to por...
2
2009-11-26T06:08:21Z
1,801,904
<p>Another possibility would be to create a 1-dimensional array and then read/write it using functions that take 11 index arguments. You multiply out the indices (based on the max for each dimension) to calculate a position in the array. The get/set functions themselves won't be all that pretty (with 11 indices) but on...
1
2009-11-26T06:35:45Z
[ "python", "c" ]
Python - Multi-Dimensional Arrays
1,801,819
<p>Python does not provide built-in support for multi-dimensional arrays. I need to develop an <strong>11-dimensional array</strong> and a set of functions to operate on it (mostly linear algebra, vector arithmetics). However, <strong>no external library import is allowed</strong>. I have a code in C and trying to por...
2
2009-11-26T06:08:21Z
1,802,030
<p>A potentially very legible solution, though probably performance-poor, would use a dict with eleven-element tuples as keys:</p> <pre><code>&gt;&gt;&gt; d[0,1,2,3,4,5,6,7,8,9,0] = [1.0, 0.0, 0.0] </code></pre> <p>This also allows you to store the coordinate vectors and pass them around as single objects:</p> <pre>...
1
2009-11-26T07:16:22Z
[ "python", "c" ]
Python - Multi-Dimensional Arrays
1,801,819
<p>Python does not provide built-in support for multi-dimensional arrays. I need to develop an <strong>11-dimensional array</strong> and a set of functions to operate on it (mostly linear algebra, vector arithmetics). However, <strong>no external library import is allowed</strong>. I have a code in C and trying to por...
2
2009-11-26T06:08:21Z
31,830,073
<p>You could use lists:</p> <pre><code>list = [ [ [ '' for i in range(dim0) ] for j in range(dim1) ] for k in range(dim2) ] </code></pre> <p>and so on after that.</p>
0
2015-08-05T10:35:43Z
[ "python", "c" ]
Python - Multi-Dimensional Arrays
1,801,819
<p>Python does not provide built-in support for multi-dimensional arrays. I need to develop an <strong>11-dimensional array</strong> and a set of functions to operate on it (mostly linear algebra, vector arithmetics). However, <strong>no external library import is allowed</strong>. I have a code in C and trying to por...
2
2009-11-26T06:08:21Z
35,722,148
<pre><code>""" Create multi-dimensional array for given dimensions - (x1, x2, x3, ..., xn) @author: Naimish Agarwal """ def multi_dimensional_array(value, *dim): """ Create multi-dimensional array :param dim: a tuple of dimensions - (x1, x2, x3, ..., xn) :param value: value with which multi-dimension...
1
2016-03-01T11:50:39Z
[ "python", "c" ]
The Pythonic way of organizing modules and packages
1,801,878
<p>I come from a background where I normally create one file per class. I organize common classes under directories as well. This practice is intuitive to me and it has been proven to be effective in C++, PHP, JavaSript, etc. </p> <p>I am having trouble bringing this metaphor into Python: files are not just files anym...
30
2009-11-26T06:28:00Z
1,801,917
<p>As a vague guideline: more than 1 class per file is the norm for python</p> <p>also, see <a href="http://stackoverflow.com/questions/106896/how-many-python-classes-should-i-put-in-one-file">http://stackoverflow.com/questions/106896/how-many-python-classes-should-i-put-in-one-file</a></p>
2
2009-11-26T06:39:59Z
[ "python", "module", "package", "project-organization" ]
The Pythonic way of organizing modules and packages
1,801,878
<p>I come from a background where I normally create one file per class. I organize common classes under directories as well. This practice is intuitive to me and it has been proven to be effective in C++, PHP, JavaSript, etc. </p> <p>I am having trouble bringing this metaphor into Python: files are not just files anym...
30
2009-11-26T06:28:00Z
1,801,945
<p>If you want to stick to your one-class-per-file system (which is logical, don't get me wrong), you might do something like this to avoid having to refer to <code>automobile.Automobile</code>:</p> <pre><code>from automobile import Automobile car = Automobile() </code></pre> <p>However, as mentioned by cobbal, more ...
6
2009-11-26T06:48:46Z
[ "python", "module", "package", "project-organization" ]
The Pythonic way of organizing modules and packages
1,801,878
<p>I come from a background where I normally create one file per class. I organize common classes under directories as well. This practice is intuitive to me and it has been proven to be effective in C++, PHP, JavaSript, etc. </p> <p>I am having trouble bringing this metaphor into Python: files are not just files anym...
30
2009-11-26T06:28:00Z
1,801,981
<p>In a mid-sized project, I found myself with several sets of closely related classes. Several of those sets are now grouped into files; for example, the low-level network classes are all in a single <code>network</code> module. However, a few of the largest classes have been split out into their own file.</p> <p>P...
3
2009-11-26T06:59:17Z
[ "python", "module", "package", "project-organization" ]
The Pythonic way of organizing modules and packages
1,801,878
<p>I come from a background where I normally create one file per class. I organize common classes under directories as well. This practice is intuitive to me and it has been proven to be effective in C++, PHP, JavaSript, etc. </p> <p>I am having trouble bringing this metaphor into Python: files are not just files anym...
30
2009-11-26T06:28:00Z
1,801,992
<p>Think in terms of a "logical unit of packaging" -- which may be a single class, but more often will be a set of classes that closely cooperate. Classes (or module-level functions -- don't "do Java in Python" by always using static methods when module-level functions are also available as a choice!-) can be grouped ...
30
2009-11-26T07:02:23Z
[ "python", "module", "package", "project-organization" ]
The Pythonic way of organizing modules and packages
1,801,878
<p>I come from a background where I normally create one file per class. I organize common classes under directories as well. This practice is intuitive to me and it has been proven to be effective in C++, PHP, JavaSript, etc. </p> <p>I am having trouble bringing this metaphor into Python: files are not just files anym...
30
2009-11-26T06:28:00Z
1,802,001
<p>If you are coming from a c++ point of view, you could view python modules akin to a .so or .dll. Yeah they look like source files, because python is scripted, but they are actually loadable libraries of specific functionality. </p> <p>Another metaphor that may help is you might look python modules as namespaces.</p...
8
2009-11-26T07:06:51Z
[ "python", "module", "package", "project-organization" ]
Using a hash function to give a memorable personality to objects
1,802,094
<p>(Note: The project is in Python.)</p> <p>I'm running a simulation in which I have many objects that I want to show on the screen and manipulate with. There needs to be a way to identify each object, because they'll be moving from place to place abruptly and I want to be able to track which object moved where.</p> ...
3
2009-11-26T07:33:33Z
1,802,103
<p>use a uuid (module uuid in python >= 2.5).</p> <p>This uuid, in version 4, is by definition random on all fields (except one)</p> <pre><code>&gt;&gt;&gt; uuid.uuid4() UUID('9d477dc7-a986-4e3d-aa4f-6e57f690be78') </code></pre> <p>You can decompose the fields properly to create a color or a name (by mapping a bucke...
2
2009-11-26T07:35:36Z
[ "python", "hash", "identification" ]
Python MySQLdb: Update if exists, else insert
1,802,172
<p>I am looking for a simple way to query an update or insert based on if the row exists in the first place. I am trying to use Python's MySQLdb right now. This is how I execute my query:</p> <pre><code>self.cursor.execute("""UPDATE `inventory` SET `quantity` = `quantity`+{1} ...
2
2009-11-26T07:55:30Z
1,802,191
<p>Mysql DOES allow you to have unique indexes, and INSERT ... ON DUPLICATE UPDATE will do the update if any unique index has a duplicate, not just the PK.</p> <p>However, I'd probably still go for the "two queries" approach. You are doing this in a transaction, right?</p> <ol> <li>Do the update</li> <li>Check the ro...
2
2009-11-26T08:01:02Z
[ "python", "sql", "sql-update", "sql-insert" ]
What the mechanism use to integrate python with other languages (.Net, Java ....)
1,802,256
<p>Somebody talking the python's code can embed into C#'s code. What the mechanism to do that? please explain for me.</p> <p>Thanks a lot</p>
1
2009-11-26T08:20:05Z
1,802,270
<p>Use <a href="http://www.codeplex.com/IronPython" rel="nofollow">IronPython</a> for integration with .net. Likewise, <a href="http://www.jython.org/" rel="nofollow">Jython</a> integrates with Java.</p>
5
2009-11-26T08:22:09Z
[ "java", ".net", "python", "embed" ]
What the mechanism use to integrate python with other languages (.Net, Java ....)
1,802,256
<p>Somebody talking the python's code can embed into C#'s code. What the mechanism to do that? please explain for me.</p> <p>Thanks a lot</p>
1
2009-11-26T08:20:05Z
1,802,272
<p>And <a href="http://www.jython.org/" rel="nofollow">Jython</a> for integration with Java.</p>
2
2009-11-26T08:23:07Z
[ "java", ".net", "python", "embed" ]
What the mechanism use to integrate python with other languages (.Net, Java ....)
1,802,256
<p>Somebody talking the python's code can embed into C#'s code. What the mechanism to do that? please explain for me.</p> <p>Thanks a lot</p>
1
2009-11-26T08:20:05Z
1,802,290
<p>There are several approaches to this, depending on which languages you want to interoperate with.</p> <ul> <li><strong>.Net/CLR Languages</strong> - <a href="http://www.codeplex.com/wikipage?ProjectName=IronPython" rel="nofollow">Iron Python</a> provides an implementation of Python running on the CLR. Allows you to...
6
2009-11-26T08:29:17Z
[ "java", ".net", "python", "embed" ]
What is paste script?
1,802,282
<p>I'm trying to understand what paste script and paster are. The website is far from clear. I used paster to generate pre-made layouts for projects, but I don't get the big picture. </p> <p>As far as I understand, and from the wikipedia entry, it says it's a framework for web frameworks, but that seems reductive. <co...
16
2009-11-26T08:26:37Z
1,802,440
<p>Paste got several components:</p> <ul> <li>Paste Core: various modules to aid in creating wsgi web apps or frameworks (<a href="http://pythonpaste.org/modindex.html">module index</a>). Includes stuff like request and response objects. From the web site: "The future of these pieces is to split them into independent ...
11
2009-11-26T09:02:40Z
[ "python", "paste", "paster" ]
What is paste script?
1,802,282
<p>I'm trying to understand what paste script and paster are. The website is far from clear. I used paster to generate pre-made layouts for projects, but I don't get the big picture. </p> <p>As far as I understand, and from the wikipedia entry, it says it's a framework for web frameworks, but that seems reductive. <co...
16
2009-11-26T08:26:37Z
1,802,443
<p>PasteScript (and its companion PasteDeploy) are tools for running Python code using 'entry points'. Basically, a python library can specify in metadata that it knows how to create a certain kind of Python project, or perform certain operations on those projects. paster is a commandline tool that looks up the appropr...
3
2009-11-26T09:03:14Z
[ "python", "paste", "paster" ]
python for in control structure
1,802,415
<p>I am a php programmer trying to understand python's for in syntax I get the basic <a href="http://docs.python.org/tutorial/controlflow.html#for-statements" rel="nofollow">for in</a></p> <pre><code>for i in range(0,5): </code></pre> <p>in php would be</p> <pre><code>for ($i = 0; $i &lt; 5; $i++){ </code></pre> <p...
1
2009-11-26T08:59:05Z
1,802,449
<p><code>self._v_scaleInfo:</code> is an array of tuples, presumably, like <code>[(x,y),(x,y),...]</code> so <code>for width, height in self._v_scaleInfo:</code> loops through the array filling width and height with the tuple values.</p> <p>php would go something like:</p> <pre><code>$scaleInfo = array(array(x,y), a...
1
2009-11-26T09:05:02Z
[ "php", "python", "for-loop" ]
python for in control structure
1,802,415
<p>I am a php programmer trying to understand python's for in syntax I get the basic <a href="http://docs.python.org/tutorial/controlflow.html#for-statements" rel="nofollow">for in</a></p> <pre><code>for i in range(0,5): </code></pre> <p>in php would be</p> <pre><code>for ($i = 0; $i &lt; 5; $i++){ </code></pre> <p...
1
2009-11-26T08:59:05Z
1,802,451
<p>In your simple example <code>for x,y in z</code>, z would be a list of coordinate pairs, like <code>[(0,1), (2,5), (4,3)]</code>. With each turn through the for loop, the <code>x</code> variable gets the first coordinate in the pair and <code>y</code> gets the second.</p>
1
2009-11-26T09:05:32Z
[ "php", "python", "for-loop" ]
python for in control structure
1,802,415
<p>I am a php programmer trying to understand python's for in syntax I get the basic <a href="http://docs.python.org/tutorial/controlflow.html#for-statements" rel="nofollow">for in</a></p> <pre><code>for i in range(0,5): </code></pre> <p>in php would be</p> <pre><code>for ($i = 0; $i &lt; 5; $i++){ </code></pre> <p...
1
2009-11-26T08:59:05Z
1,802,455
<p>It's roughly equivalent to (pseudo code):</p> <pre><code>For every item i in z: x = i[0] y = i[1] Loop body happens here </code></pre> <p>It means that every item in <code>z</code> contains 2 elements (for example, every item is a list with 2 items).</p>
0
2009-11-26T09:06:04Z
[ "php", "python", "for-loop" ]
python for in control structure
1,802,415
<p>I am a php programmer trying to understand python's for in syntax I get the basic <a href="http://docs.python.org/tutorial/controlflow.html#for-statements" rel="nofollow">for in</a></p> <pre><code>for i in range(0,5): </code></pre> <p>in php would be</p> <pre><code>for ($i = 0; $i &lt; 5; $i++){ </code></pre> <p...
1
2009-11-26T08:59:05Z
1,802,470
<p>In python, you can have multiple return values. You can also define a tuple like this</p> <pre><code>t = (1,2,3) </code></pre> <p>To get access to the elements in t you can do the following:</p> <blockquote> <p>a, b, c = t</p> </blockquote> <p>Then a has the value 1, etc.</p> <p>If you had an array of 2 eleme...
0
2009-11-26T09:08:35Z
[ "php", "python", "for-loop" ]
python for in control structure
1,802,415
<p>I am a php programmer trying to understand python's for in syntax I get the basic <a href="http://docs.python.org/tutorial/controlflow.html#for-statements" rel="nofollow">for in</a></p> <pre><code>for i in range(0,5): </code></pre> <p>in php would be</p> <pre><code>for ($i = 0; $i &lt; 5; $i++){ </code></pre> <p...
1
2009-11-26T08:59:05Z
1,802,485
<p>Suppose z is a list of tuples in Python.</p> <pre><code>Z = [(1,2), (1,3), (2,3), (2,4)] </code></pre> <p>it would be something like:</p> <pre><code>$z = array(array(1,2), array(1,3), array(2,3), array(2,4)); </code></pre> <p>using that for x,y in z would result in:</p> <pre><code>z = [(1,2), (1,3), (2,3), (2,4...
0
2009-11-26T09:11:48Z
[ "php", "python", "for-loop" ]
python for in control structure
1,802,415
<p>I am a php programmer trying to understand python's for in syntax I get the basic <a href="http://docs.python.org/tutorial/controlflow.html#for-statements" rel="nofollow">for in</a></p> <pre><code>for i in range(0,5): </code></pre> <p>in php would be</p> <pre><code>for ($i = 0; $i &lt; 5; $i++){ </code></pre> <p...
1
2009-11-26T08:59:05Z
1,802,505
<p>Conceptually</p> <pre><code>for x,y in z </code></pre> <p>is actually iterating using an enumerator (language specific implementation of an iterator pattern), for loops are based on index based iteration.</p> <p>for x,y in z would semantically be like</p> <pre><code>for (x=0 ; x&lt;z.length ; x++ ) for (y=1...
0
2009-11-26T09:16:02Z
[ "php", "python", "for-loop" ]
python for in control structure
1,802,415
<p>I am a php programmer trying to understand python's for in syntax I get the basic <a href="http://docs.python.org/tutorial/controlflow.html#for-statements" rel="nofollow">for in</a></p> <pre><code>for i in range(0,5): </code></pre> <p>in php would be</p> <pre><code>for ($i = 0; $i &lt; 5; $i++){ </code></pre> <p...
1
2009-11-26T08:59:05Z
1,802,935
<p>This construct allows you to iterate over multi-dimensional collections so for a 3x2 list you could have have:</p> <pre><code>z = [[1,2], [3,4], [5,6]] for x, y in z: print x, y </code></pre> <p>This prints:</p> <pre><code>1 2 3 4 5 6 </code></pre> <p>The same construct could be used on a dictionary which is...
0
2009-11-26T10:42:10Z
[ "php", "python", "for-loop" ]
How to identify whether a variable is a class or an object
1,802,480
<p>I am working at a bit lower level writing a small framework for creating test fixtures for my project in Python. In this I want to find out whether a particular variable is an instance of a certain class or a class itself and if it is a class, I want to know if it is a subclass of a certain class defined by my frame...
3
2009-11-26T09:11:14Z
1,802,506
<p>Use the <code>type()</code> function. It will return the type of the object. You can get 'stock' types to match with from the <a href="http://docs.python.org/library/types.html" rel="nofollow">types</a> library. Old-style classes (that don't inherit from anything) have the type <code>types.ClassType</code>. New-styl...
3
2009-11-26T09:16:08Z
[ "python" ]
How to identify whether a variable is a class or an object
1,802,480
<p>I am working at a bit lower level writing a small framework for creating test fixtures for my project in Python. In this I want to find out whether a particular variable is an instance of a certain class or a class itself and if it is a class, I want to know if it is a subclass of a certain class defined by my frame...
3
2009-11-26T09:11:14Z
1,802,507
<p>Use <code>isinstance</code> and <code>type</code>, <code>types.ClassType</code> (that latter is for old-style classes):</p> <pre><code>&gt;&gt;&gt; isinstance(int, type) True &gt;&gt;&gt; isinstance(1, type) False </code></pre>
4
2009-11-26T09:16:10Z
[ "python" ]
How to identify whether a variable is a class or an object
1,802,480
<p>I am working at a bit lower level writing a small framework for creating test fixtures for my project in Python. In this I want to find out whether a particular variable is an instance of a certain class or a class itself and if it is a class, I want to know if it is a subclass of a certain class defined by my frame...
3
2009-11-26T09:11:14Z
1,802,520
<p>Use type()</p> <pre><code>&gt;&gt;&gt; class A: pass &gt;&gt;&gt; print type(A) &lt;type 'classobj'&gt; &gt;&gt;&gt; A = "abc" &gt;&gt;&gt; print type(A) &lt;type 'str'&gt; </code></pre>
1
2009-11-26T09:18:37Z
[ "python" ]
How to identify whether a variable is a class or an object
1,802,480
<p>I am working at a bit lower level writing a small framework for creating test fixtures for my project in Python. In this I want to find out whether a particular variable is an instance of a certain class or a class itself and if it is a class, I want to know if it is a subclass of a certain class defined by my frame...
3
2009-11-26T09:11:14Z
1,802,533
<p>Use the <a href="http://docs.python.org/library/inspect.html#module-inspect">inspect module</a>.</p> <blockquote> <p>The inspect module provides several useful functions to help get information about live objects such as modules, classes, methods, functions, tracebacks, frame objects, and code objects. For exampl...
11
2009-11-26T09:19:56Z
[ "python" ]
How to get the arch string that distutils uses for builds?
1,802,534
<p>When I build a c extension using <code>python setup.py build</code>, the result is created under a directory named</p> <pre><code>build/lib.linux-x86_64-2.6/ </code></pre> <p>where the part after <code>lib.</code> changes by the OS, CPU and Python version.</p> <p>Is there a way I can access the appropriate string...
3
2009-11-26T09:20:09Z
1,802,626
<pre><code>&gt;&gt;&gt; from distutils import util &gt;&gt;&gt; util.get_platform() 'linux-x86_64' &gt;&gt;&gt; import sys &gt;&gt;&gt; '%s.%s' % sys.version_info[:2] 2.6 </code></pre>
3
2009-11-26T09:41:26Z
[ "python", "distutils", "python-c-extension" ]
Match UserProperty() with StringProperty()
1,802,728
<p>I want to match <code>StringProperty()</code> with <code>UserProperty</code> and I can't change property so how can I achieve it? Please help me out.</p>
0
2009-11-26T10:00:53Z
1,802,775
<p>You seem to be talking about Google App Engine's model properties. To the best of my knowledge, you can't query a UserProperty with a string, because a User is not a string. Instead, try creating a brand new <a href="http://code.google.com/appengine/docs/python/users/userclass.html" rel="nofollow">User object</a>; y...
0
2009-11-26T10:10:51Z
[ "python" ]