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 |
|---|---|---|---|---|---|---|---|---|---|
Classify array of strings based on commonalities | 1,719,865 | <p>I have huge list (200000) of strings (multi word). I want to group these strings based on comman array of word match among these strings. I cant think of a low computation time algorithm for this</p>
<p>"<strong>AB 500</strong>"<br>
"Bus <strong>AB 500</strong>"<br>
"<strong>News CA</strong>"<br>
"<strong>Ne... | 1 | 2009-11-12T04:22:55Z | 1,728,395 | <p>What would happen, if the string "AB 500 News CA" is added to your list? Do the two groups of strings have to merge? If not, how to split up the list of strings and why?</p>
<p>A very general workflow for problems like this (if i understood it correctly) goes like this:</p>
<ol>
<li>Get a list of candidate pairs v... | 0 | 2009-11-13T10:29:02Z | [
"python",
"string",
"algorithm",
"classification"
] |
Django unit testing - Why can't I just run ./tests.py on myApp? | 1,719,883 | <p>So I'm very familiar with <code>manage.py test myapp</code>. But I can't figure out how to make my <code>tests.py</code> work as an stand-alone executable. You may be wondering why I would want to do this.. Well I'm working (<em>now</em>) in Eclipse and I can't seem to figure out how to set up the tool to simply r... | 0 | 2009-11-12T04:29:46Z | 1,719,976 | <p>a. this should be the first line at your code file (tests.py)</p>
<pre><code>#!/usr/bin/env python
</code></pre>
<p>b. run <code>$ chmod +x tests.py</code> </p>
| -1 | 2009-11-12T04:57:02Z | [
"python",
"django",
"eclipse",
"unit-testing",
"pydev"
] |
Django unit testing - Why can't I just run ./tests.py on myApp? | 1,719,883 | <p>So I'm very familiar with <code>manage.py test myapp</code>. But I can't figure out how to make my <code>tests.py</code> work as an stand-alone executable. You may be wondering why I would want to do this.. Well I'm working (<em>now</em>) in Eclipse and I can't seem to figure out how to set up the tool to simply r... | 0 | 2009-11-12T04:29:46Z | 1,724,088 | <p>You could create an "External Tool" configuration for your project, such as:</p>
<pre><code>Location: ${project_loc}/src/${project_name}/manage.py
Working Directory: ${project_loc}/src/${project_name}/
Arguments: test ${string_prompt}
</code></pre>
<p>This will run manage.py test <whatever name you type in the ... | 1 | 2009-11-12T17:47:13Z | [
"python",
"django",
"eclipse",
"unit-testing",
"pydev"
] |
How does pylint quit the Windows command box it is running in? | 1,719,898 | <p>Pylint is doing something odd on my Windows box - something that shouldn't be possible. This isn't a question about fixing pylint, so much as fixing my understanding.</p>
<p>I have a typical install of the latest version of pylint, Python 2.6 and Windows Vista.</p>
<p>If I open a Command Prompt, and run pylint fro... | 0 | 2009-11-12T04:33:33Z | 1,720,007 | <p>I just tried this on XP:</p>
<p>t.bat:</p>
<blockquote>
<p><code>exit</code></p>
</blockquote>
<p>Running this closes the window!</p>
<p>Maybe the command line for pylint uses a batch file which contains an exit?</p>
| 2 | 2009-11-12T05:04:16Z | [
"python",
"command-line",
"windows-vista",
"pylint",
"errorlevel"
] |
How does pylint quit the Windows command box it is running in? | 1,719,898 | <p>Pylint is doing something odd on my Windows box - something that shouldn't be possible. This isn't a question about fixing pylint, so much as fixing my understanding.</p>
<p>I have a typical install of the latest version of pylint, Python 2.6 and Windows Vista.</p>
<p>If I open a Command Prompt, and run pylint fro... | 0 | 2009-11-12T04:33:33Z | 1,777,325 | <p>This is a very easy fix. Go into your python scripts folder and locate pylint.bat and open it in notepad.</p>
<p>It will read the following</p>
<pre><code>@echo off
rem = """-*-Python-*- script
rem -------------------- DOS section --------------------
rem You could set PYTHONPATH or TK environment variables here
... | 1 | 2009-11-22T00:35:59Z | [
"python",
"command-line",
"windows-vista",
"pylint",
"errorlevel"
] |
How does pylint quit the Windows command box it is running in? | 1,719,898 | <p>Pylint is doing something odd on my Windows box - something that shouldn't be possible. This isn't a question about fixing pylint, so much as fixing my understanding.</p>
<p>I have a typical install of the latest version of pylint, Python 2.6 and Windows Vista.</p>
<p>If I open a Command Prompt, and run pylint fro... | 0 | 2009-11-12T04:33:33Z | 2,336,485 | <p>This is <a href="http://www.logilab.org/ticket/19498" rel="nofollow">http://www.logilab.org/ticket/19498</a> scheduled for 0.20.0 (currently under development). </p>
| 1 | 2010-02-25T18:15:09Z | [
"python",
"command-line",
"windows-vista",
"pylint",
"errorlevel"
] |
Filtering odd numbers | 1,719,929 | <pre><code>M = [[1,2,3],
[4,5,6],
[7,8,9]]
col2 = [row[1] + 1 for row in M if row[1] % 2 == 0]
print (col2)
</code></pre>
<p>Output: <code>[3, 9]</code></p>
<p>I'm expecting it to filter out the odd numbers, but it does the opposite.</p>
| 2 | 2009-11-12T04:43:30Z | 1,719,946 | <p>The code is doing exactly what you would expect - if the second item is even, increase it by one and put it into the list.</p>
<p>So for the first row, it sees that 2 % 2 == 0 is True, and sets col2[0] = 2 + 1 = 3. For the second row, 5 % 2 == 0 is False. For the third row, 8%2 == 0 is True, and col2[1] = 8 + 1 = 9... | 6 | 2009-11-12T04:46:45Z | [
"python",
"list-comprehension",
"modulo"
] |
Filtering odd numbers | 1,719,929 | <pre><code>M = [[1,2,3],
[4,5,6],
[7,8,9]]
col2 = [row[1] + 1 for row in M if row[1] % 2 == 0]
print (col2)
</code></pre>
<p>Output: <code>[3, 9]</code></p>
<p>I'm expecting it to filter out the odd numbers, but it does the opposite.</p>
| 2 | 2009-11-12T04:43:30Z | 1,719,957 | <p>You are testing <code>row[1]%2</code>, but printing <code>row[1]+1</code><br>
so when <code>row[1]==2</code>, it is even, but you are appending <code>3</code> to the result<br>
when <code>row[1]==5</code>, it is odd, so you filter it out<br>
and when <code>row[1]==8</code>, it is even, but you are appending <code>9<... | 0 | 2009-11-12T04:50:27Z | [
"python",
"list-comprehension",
"modulo"
] |
Filtering odd numbers | 1,719,929 | <pre><code>M = [[1,2,3],
[4,5,6],
[7,8,9]]
col2 = [row[1] + 1 for row in M if row[1] % 2 == 0]
print (col2)
</code></pre>
<p>Output: <code>[3, 9]</code></p>
<p>I'm expecting it to filter out the odd numbers, but it does the opposite.</p>
| 2 | 2009-11-12T04:43:30Z | 1,719,959 | <p>I believe you need to switch the comparison to <code>== 1</code> from <code>== 0</code>.</p>
<p>The modulus of any number divided by 2 is 0 or 1, 1 when it is odd.</p>
| 2 | 2009-11-12T04:50:48Z | [
"python",
"list-comprehension",
"modulo"
] |
Filtering odd numbers | 1,719,929 | <pre><code>M = [[1,2,3],
[4,5,6],
[7,8,9]]
col2 = [row[1] + 1 for row in M if row[1] % 2 == 0]
print (col2)
</code></pre>
<p>Output: <code>[3, 9]</code></p>
<p>I'm expecting it to filter out the odd numbers, but it does the opposite.</p>
| 2 | 2009-11-12T04:43:30Z | 1,719,995 | <pre><code>M = [[1,2,3],
[4,5,6],
[7,8,9]]
col2 = []
for row in M:
if row[1]%2 == 1:
col2.append(row[1])
print col2
</code></pre>
| 0 | 2009-11-12T05:02:01Z | [
"python",
"list-comprehension",
"modulo"
] |
Configure "execute shell" scripts in Hudson with Python | 1,719,977 | <p>I am using <a href="http://hudson-ci.org/" rel="nofollow">Hudson</a> for continuous integration in our project. We are using python, git and nose tests for unit testing. What I need is that Hudson should execute nose tests after every build. For that I have added following shell scripts in under execute shell sectio... | 1 | 2009-11-12T04:57:19Z | 3,567,330 | <p>For my own project, I wrote a <a href="http://docs.fabfile.org/0.9.1/" rel="nofollow">fabric</a> python files that manage all the unit testing. Since I am using django, I have django incorporate with nose and coverage.</p>
<p>Here are my part of my scripts:</p>
<pre><code>local('%(local_virtual_env)s/Scripts/activ... | 0 | 2010-08-25T15:07:36Z | [
"python",
"continuous-integration",
"hudson",
"nosetests"
] |
Configure "execute shell" scripts in Hudson with Python | 1,719,977 | <p>I am using <a href="http://hudson-ci.org/" rel="nofollow">Hudson</a> for continuous integration in our project. We are using python, git and nose tests for unit testing. What I need is that Hudson should execute nose tests after every build. For that I have added following shell scripts in under execute shell sectio... | 1 | 2009-11-12T04:57:19Z | 16,069,756 | <p>I'd take advantage of nose's ability to find the tests and run them instead.</p>
<p>Rename your test files to something like sub/sample1_test.py, sub/sample2_test.py, etc., and then just run </p>
<pre><code>nosetests sub/
</code></pre>
<p>Nose will look for files ending in _test and run them. Very handy. See the ... | 1 | 2013-04-17T20:33:57Z | [
"python",
"continuous-integration",
"hudson",
"nosetests"
] |
On Windows in python, possibly using the Outlook API, how can I get the full name of a user from their smaller login name? | 1,720,077 | <p>At work, we have short login names, e.g. <code>hastingsg</code>, but Outlook and I believe other parts of the Windows system also have access to a longer name, e.g. Jeff Hastings.</p>
<p>In cpython (not IronPython), if I have the shorter login name, how can I get the longer full name? I have <a href="http://source... | 1 | 2009-11-12T05:27:38Z | 1,720,143 | <p>I think you can query your Exchange Server Active Directory with a <a href="http://timgolden.me.uk/python/active%5Fdirectory.html" rel="nofollow">dedicated module</a></p>
<p>(not tested):</p>
<pre><code>import active_directory
user = active_directory.find_user("hastingsg")
print user.displayName
</code></pre>
| 1 | 2009-11-12T05:45:07Z | [
"python",
"windows",
"outlook",
"pywin32"
] |
On Windows in python, possibly using the Outlook API, how can I get the full name of a user from their smaller login name? | 1,720,077 | <p>At work, we have short login names, e.g. <code>hastingsg</code>, but Outlook and I believe other parts of the Windows system also have access to a longer name, e.g. Jeff Hastings.</p>
<p>In cpython (not IronPython), if I have the shorter login name, how can I get the longer full name? I have <a href="http://source... | 1 | 2009-11-12T05:27:38Z | 1,720,146 | <p>Via the COM parts of <code>pywin32</code>, you need to get Outlook's Application object, and from it its attribute <code>Session</code>, which gives you the <a href="http://msdn.microsoft.com/en-us/library/bb176693.aspx" rel="nofollow">Namespace</a> object (the <code>GetNamespace</code> method should also work for t... | 2 | 2009-11-12T05:45:48Z | [
"python",
"windows",
"outlook",
"pywin32"
] |
On Windows in python, possibly using the Outlook API, how can I get the full name of a user from their smaller login name? | 1,720,077 | <p>At work, we have short login names, e.g. <code>hastingsg</code>, but Outlook and I believe other parts of the Windows system also have access to a longer name, e.g. Jeff Hastings.</p>
<p>In cpython (not IronPython), if I have the shorter login name, how can I get the longer full name? I have <a href="http://source... | 1 | 2009-11-12T05:27:38Z | 1,720,233 | <p>May be you need TranslateName api e.g. play with something like this, 2ns /3rd argument can be constants from <a href="http://msdn.microsoft.com/en-us/library/ms724268%28VS.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms724268%28VS.85%29.aspx</a></p>
<pre><code>win32security.TranslateName(win3... | 0 | 2009-11-12T06:08:13Z | [
"python",
"windows",
"outlook",
"pywin32"
] |
What is the Yahoo openid discovery endpoint | 1,720,097 | <p>It used to be <a href="http://yahoo.com">http://yahoo.com</a>, but it is failing for me with DiscoveryFailure in python OpenID library (since today, I wasn't testing this earlier). Also this fails if you try to use the SO login with a yahoo button, so I am thinking it probably changed recently.</p>
| 5 | 2009-11-12T05:31:08Z | 1,720,265 | <p>I noticed it was down a few hours ago. It isn't working for any RP I've tried... except for zoho.com</p>
<p>I viewed their source and saw they are using <strong><a href="https://me.yahoo.com" rel="nofollow">https://me.yahoo.com</a></strong>, which works.</p>
<p>Yahoo either made a mistake in a recent site change,... | 7 | 2009-11-12T06:18:10Z | [
"python",
"openid",
"yahoo"
] |
What is the Yahoo openid discovery endpoint | 1,720,097 | <p>It used to be <a href="http://yahoo.com">http://yahoo.com</a>, but it is failing for me with DiscoveryFailure in python OpenID library (since today, I wasn't testing this earlier). Also this fails if you try to use the SO login with a yahoo button, so I am thinking it probably changed recently.</p>
| 5 | 2009-11-12T05:31:08Z | 9,421,385 | <p>The problem only occurs on <em>some</em> yahoo servers - look up IPs for yahoo.com, and during YADIS resolution, some will work, and some won't. So that's why it works in some places and not others.</p>
<p>Per Yahoo ( <a href="http://developer.yahoo.com/forum/OpenID-General-Discussion/http-www-yahoo-com-returns-404... | 0 | 2012-02-23T21:12:20Z | [
"python",
"openid",
"yahoo"
] |
What is the Yahoo openid discovery endpoint | 1,720,097 | <p>It used to be <a href="http://yahoo.com">http://yahoo.com</a>, but it is failing for me with DiscoveryFailure in python OpenID library (since today, I wasn't testing this earlier). Also this fails if you try to use the SO login with a yahoo button, so I am thinking it probably changed recently.</p>
| 5 | 2009-11-12T05:31:08Z | 12,000,141 | <p>Is Openid url for Yahoo <a href="https://me.yahoo.com" rel="nofollow">https://me.yahoo.com</a> only. I thought it is
<a href="http://me.yahoo.com/profile-name" rel="nofollow">http://me.yahoo.com/profile-name</a> . profile-name is chosen by the user at the time of selection of his openid url. </p>
| 0 | 2012-08-17T05:15:41Z | [
"python",
"openid",
"yahoo"
] |
Diference between appengine_django BaseModel and db.Model | 1,720,157 | <p>I'm using the Google App Engine helper for Django. This helper includes the following lines in its template:</p>
<pre><code>from appengine_django.models import BaseModel
from google.appengine.ext import db
# Create your models here.
</code></pre>
<p>Should I derive my models from db.Model or from BaseModel?
I've ... | 1 | 2009-11-12T05:49:32Z | 1,720,780 | <p>BaseModel is a class defined by the Django helper. It extends db.Model in order to make Django work with it better. The reason you need to import both is because the property classes are still used directly from db - but if you use db.Model instead of BaseModel, you may find some features of Django that don't work a... | 0 | 2009-11-12T08:38:07Z | [
"python",
"django",
"google-app-engine",
"django-models"
] |
Diference between appengine_django BaseModel and db.Model | 1,720,157 | <p>I'm using the Google App Engine helper for Django. This helper includes the following lines in its template:</p>
<pre><code>from appengine_django.models import BaseModel
from google.appengine.ext import db
# Create your models here.
</code></pre>
<p>Should I derive my models from db.Model or from BaseModel?
I've ... | 1 | 2009-11-12T05:49:32Z | 1,722,106 | <p>The BaseModel also does a registration of the inherited model inside django (so f.e. you can request it by calling django.db.models.loading.get_model('app_lable.ModelName') and all other stuff related to this)</p>
| 1 | 2009-11-12T13:15:22Z | [
"python",
"django",
"google-app-engine",
"django-models"
] |
What does this Python code do: shell=(sys.platform!="win32")) | 1,720,169 | <p>I don't understand what this code is doing,
I'm wanting to run a command line, in Mac OS X, the code I'm using is from somebody running a Windows command line. The command still executes, but I'd like to know what the sys.platform!="win32" is for, and if I should change it to something else for Mac OS X. It seem... | 1 | 2009-11-12T05:51:49Z | 1,720,192 | <p>Here is what this code does and does not:</p>
<ul>
<li>It doesn't compile (syntax error -
you need a comma between the
arguments) , - not anymore.</li>
<li>It starts a subprocess
and, if you are not on win32 it
starts it through the shell. The
"shell" argument can be True or
False and <code>sys.platform != 'win32'<... | 5 | 2009-11-12T05:55:47Z | [
"python",
"osx",
"command-line"
] |
What does this Python code do: shell=(sys.platform!="win32")) | 1,720,169 | <p>I don't understand what this code is doing,
I'm wanting to run a command line, in Mac OS X, the code I'm using is from somebody running a Windows command line. The command still executes, but I'd like to know what the sys.platform!="win32" is for, and if I should change it to something else for Mac OS X. It seem... | 1 | 2009-11-12T05:51:49Z | 1,720,200 | <p>Same as :</p>
<pre><code>if sys.platform!="win32":
return_code = subprocess.call(str(cline), shell=True)
else
return_code = subprocess.call(str(cline), shell=False)
</code></pre>
<p>see <a href="http://docs.python.org/library/subprocess.html" rel="nofollow">subprocess doc</a> (execute <code>cline</code>)</... | 2 | 2009-11-12T05:57:47Z | [
"python",
"osx",
"command-line"
] |
Remove first 4 letters from a folder name using Bash scripting | 1,720,286 | <p>As the title says I want to remove the first 4 letters from a folder name using a <a href="http://en.wikipedia.org/wiki/Bash" rel="nofollow">Bash</a> script. If you have another way to do it in Linux I don't really mind e.g. Python. Also I need the script to be executed regularly (daily).</p>
| 1 | 2009-11-12T06:23:42Z | 1,720,294 | <p>Since you don't mention to rename a directory or so, I assume you want simple string editing. If you want more, you should ask the right questions.</p>
<pre><code># name of the DIRECTORY (not ''folder''...)
name=fooodir
# compute a new name
editedname=${name#????}
echo "${editedname}"
</code></pre>
| 3 | 2009-11-12T06:27:37Z | [
"python",
"linux",
"bash"
] |
Remove first 4 letters from a folder name using Bash scripting | 1,720,286 | <p>As the title says I want to remove the first 4 letters from a folder name using a <a href="http://en.wikipedia.org/wiki/Bash" rel="nofollow">Bash</a> script. If you have another way to do it in Linux I don't really mind e.g. Python. Also I need the script to be executed regularly (daily).</p>
| 1 | 2009-11-12T06:23:42Z | 1,720,330 | <p>Another way in Bash:</p>
<pre><code>$ dname=mydirectory
$ echo ${dname:4}
rectory
</code></pre>
| 9 | 2009-11-12T06:39:11Z | [
"python",
"linux",
"bash"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 1,720,432 | <p>Python makes this ridiculously easy.</p>
<pre><code>mergedlist = listone + listtwo
</code></pre>
| 1,574 | 2009-11-12T07:07:06Z | [
"python",
"list"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 1,720,436 | <p>This is quite simple, I think it was even shown in the <a href="http://docs.python.org/tutorial/">tutorial</a>:</p>
<pre><code>>>> listone = [1,2,3]
>>> listtwo = [4,5,6]
>>>
>>> listone + listtwo
[1, 2, 3, 4, 5, 6]
</code></pre>
| 38 | 2009-11-12T07:07:37Z | [
"python",
"list"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 1,724,975 | <p>It's also possible to create a generator that simply iterates over the items in both lists. This allows you to chain lists (or any iterable) together for processing without copying the items to a new list:</p>
<pre><code>import itertools
for item in itertools.chain(listone, listtwo):
# do something with each li... | 133 | 2009-11-12T20:01:50Z | [
"python",
"list"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 3,749,835 | <p>You can use sets to obtain merged list of unique values</p>
<pre><code>mergedlist = list(set(listone + listtwo))
</code></pre>
| 101 | 2010-09-20T08:43:58Z | [
"python",
"list"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 14,453,876 | <p>You could also use <a href="https://docs.python.org/2.7/tutorial/datastructures.html#more-on-lists"><code>extend</code></a> in order to add a <code>list</code> add the end of another one:</p>
<pre><code>listone = [1,2,3]
listtwo = [4,5,6]
mergedlist = []
mergedlist.extend(listone)
mergedlist.extend(listtwo)
</code>... | 43 | 2013-01-22T07:51:41Z | [
"python",
"list"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 14,700,501 | <p>It's worth noting that the <code>itertools.chain</code> function accepts variable number of arguments:</p>
<pre><code>>>> l1 = ['a']; l2 = ['b', 'c']; l3 = ['d', 'e', 'f']
>>> [i for i in itertools.chain(l1, l2)]
['a', 'b', 'c']
>>> [i for i in itertools.chain(l1, l2, l3)]
['a', 'b', 'c',... | 16 | 2013-02-05T05:01:34Z | [
"python",
"list"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 15,219,904 | <p>You could simply use the <code>+</code> or <code>+=</code> operator as follows:</p>
<pre><code>a = [1, 2, 3]
b = [4, 5, 6]
c = a + b
</code></pre>
<p>Or:</p>
<pre><code>c = []
a = [1, 2, 3]
b = [4, 5, 6]
c += (a + b)
</code></pre>
<p>Also, if you want the values in the merged list to be unique you can do:</p>
... | 23 | 2013-03-05T09:15:56Z | [
"python",
"list"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 17,666,852 | <p>You could use the <code>append()</code> method defined on <code>list</code> objects: </p>
<pre><code>mergedlist =[]
for elem in listone:
mergedlist.append(elem)
for elem in listtwo:
mergedlist.append(elem)
</code></pre>
| 3 | 2013-07-16T02:02:49Z | [
"python",
"list"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 19,843,368 | <p>If you need to merge two ordered lists with complicated sorting rules, you might have to roll it yourself like in the following code (using a simple sorting rule for readability :-) ).</p>
<pre><code>list1 = [1,2,5]
list2 = [2,3,4]
newlist = []
while list1 and list2:
if list1[0] == list2[0]:
newlist.ap... | 5 | 2013-11-07T18:04:54Z | [
"python",
"list"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 24,856,361 | <p>With Python 3.3+ you can use <a href="https://docs.python.org/3/whatsnew/3.3.html#pep-380">yield from</a>:</p>
<pre><code>listone = [1,2,3]
listtwo = [4,5,6]
def merge(l1, l2):
yield from l1
yield from l2
>>> list(merge(listone, listtwo))
[1, 2, 3, 4, 5, 6]
</code></pre>
<p>Or, if you want to su... | 12 | 2014-07-21T00:53:24Z | [
"python",
"list"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 26,462,448 | <p>If you don't want to or can't use the plus operator (<code>+</code>), you can uses the <code>__add__</code> function:</p>
<pre><code>listone = [1,2,3]
listtwo = [4,5,6]
result = list.__add__(listone, listtwo)
print(result)
>>> [1, 2, 3, 4, 5, 6]
</code></pre>
| 6 | 2014-10-20T09:32:32Z | [
"python",
"list"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 31,254,671 | <p>As a more general way for more lists you can put them within a list and use <code>itertools.chain.from_iterable()</code><sup>1</sup> function which based on <a href="http://stackoverflow.com/a/953097/2867928">THIS</a> answer is the best way for flatting a nested list :</p>
<pre><code>>>> l=[[1, 2, 3], [4, ... | 4 | 2015-07-06T20:06:35Z | [
"python",
"list"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 31,270,002 | <p>If you want to merge the two lists in sorted form, you can use merge function from the heapq library.</p>
<pre><code>from heapq import merge
a = [1,2,4]
b = [2,4,6,7]
print list(merge(a,b))
</code></pre>
| 9 | 2015-07-07T13:30:48Z | [
"python",
"list"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 32,129,292 | <pre><code>list1 = [1,2,3]
list2 = [4,5,6]
joinedlist = list1 + list2
#Output : [1, 2, 3, 4, 5, 6]
</code></pre>
<p>Yes, it's that simple.</p>
<p><code>list1 + list2</code>. This gives a new list that is the concatenation of <code>list1</code> and <code>list2</code>.</p>
| 2 | 2015-08-20T22:12:20Z | [
"python",
"list"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 32,289,201 | <p>Joining two lists in Python:</p>
<pre><code>>>> a = [1, 2, 3, 4]
>>> b = [1, 4, 6, 7]
>>> c = a + b
>>> c
[1, 2, 3, 4, 1, 4, 6, 7]
</code></pre>
<p>If you don't want any duplication:</p>
<pre><code>>>> a = [1, 2, 3, 4, 5, 6]
>>> b = [5, 6, 7, 8]
>>> c... | 4 | 2015-08-29T18:03:13Z | [
"python",
"list"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 33,048,483 | <p>This question directly asks about joining two lists. However it's pretty high in search even when you are looking for a way of joining many lists (including the case when you joining zero lists). Consider this more generic approach:</p>
<pre><code>a = [[1,2,3], [4,5,6], [7,8,9]]
reduce(lambda c, x: c + x, a, [])
</... | 7 | 2015-10-09T23:21:27Z | [
"python",
"list"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 33,484,904 | <p>As already pointed out by many, <code>itertools.chain()</code> is the way to go if one needs to apply <em>exactly the same treatment</em> to both lists. In my case, I had a label and a flag which were different from one list to the other, so I needed something slightly more complex. As it turns out, behind the scene... | 2 | 2015-11-02T18:59:02Z | [
"python",
"list"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 35,631,185 | <h3>Python <code>>= 3.5</code> alternative:</h3>
<p>Even though this is an old answer, another alternative has been introduced via the acceptance of <strong><a href="https://www.python.org/dev/peps/pep-0448/"><code>PEP 448</code></a></strong> which deserves mentioning. </p>
<p>The PEP, titled <strong><em>Additiona... | 11 | 2016-02-25T15:13:10Z | [
"python",
"list"
] |
How to append list to second list (concatenate lists) | 1,720,421 | <p>How do I concatenate two lists in Python?</p>
<p>Example:</p>
<pre><code>listone = [1, 2, 3]
listtwo = [4, 5, 6]
</code></pre>
<p>Expected outcome:</p>
<pre><code>joinedlist == [1, 2, 3, 4, 5, 6]
</code></pre>
| 919 | 2009-11-12T07:04:09Z | 38,240,019 | <pre><code>list(set(listone) | set(listtwo))
</code></pre>
<p>The above code, does not preserve order, removes duplicate from each list (but not from the concatenated list)</p>
| 2 | 2016-07-07T07:42:00Z | [
"python",
"list"
] |
Parsing people's first and last name in Python | 1,720,503 | <h2>Thanks so much everyone who helped!</h2>
<p>So basically I need to parse a name and find the following info:</p>
<p>First Name</p>
<p>First Initial (if employee has initials for a first name like D.J., use both initials)</p>
<p>Last Name (include if employee has a suffix such as Jr. or III.)</p>
<p><hr></p>
<... | 6 | 2009-11-12T07:23:58Z | 1,720,575 | <p>Well, for your simple example names, you can do something like this. </p>
<pre><code># This separates the first and last names
name = name.partition(" ")
firstName = name[0]
# now figure out the first initial
# we're assuming that if it has a dot it's an initialized name,
# but this may not hold in general
if "." i... | 3 | 2009-11-12T07:44:11Z | [
"python",
"parsing"
] |
Parsing people's first and last name in Python | 1,720,503 | <h2>Thanks so much everyone who helped!</h2>
<p>So basically I need to parse a name and find the following info:</p>
<p>First Name</p>
<p>First Initial (if employee has initials for a first name like D.J., use both initials)</p>
<p>Last Name (include if employee has a suffix such as Jr. or III.)</p>
<p><hr></p>
<... | 6 | 2009-11-12T07:23:58Z | 1,720,580 | <p>There is no general solution and solution will depend on the constraints you put. For the specs you have given here is a simple solution which gives exactly what you want</p>
<pre><code>def parse_name(name):
fl = name.split()
first_name = fl[0]
last_name = ' '.join(fl[1:])
if "." in first_name:
fi... | 3 | 2009-11-12T07:45:36Z | [
"python",
"parsing"
] |
Parsing people's first and last name in Python | 1,720,503 | <h2>Thanks so much everyone who helped!</h2>
<p>So basically I need to parse a name and find the following info:</p>
<p>First Name</p>
<p>First Initial (if employee has initials for a first name like D.J., use both initials)</p>
<p>Last Name (include if employee has a suffix such as Jr. or III.)</p>
<p><hr></p>
<... | 6 | 2009-11-12T07:23:58Z | 1,720,594 | <p>This is basically the same solution as the one Anurag Uniyal provided, only a little more compact:</p>
<pre><code>import re
def parse_name(name):
first_name, last_name = name.split(' ', 1)
first_initial = re.search("^[A-Z.]+", first_name).group()
if not first_initial.endswith("."):
first_initia... | 3 | 2009-11-12T07:50:26Z | [
"python",
"parsing"
] |
Parsing people's first and last name in Python | 1,720,503 | <h2>Thanks so much everyone who helped!</h2>
<p>So basically I need to parse a name and find the following info:</p>
<p>First Name</p>
<p>First Initial (if employee has initials for a first name like D.J., use both initials)</p>
<p>Last Name (include if employee has a suffix such as Jr. or III.)</p>
<p><hr></p>
<... | 6 | 2009-11-12T07:23:58Z | 14,681,167 | <p>I found this library quite useful for parsing names. <a href="https://code.google.com/p/python-nameparser/">https://code.google.com/p/python-nameparser/</a></p>
<p>It can also deal with names that are formatted Lastname, Firstname.</p>
| 6 | 2013-02-04T06:00:16Z | [
"python",
"parsing"
] |
how to run parallel job in python | 1,720,603 | <p>i do data mining project in python, during experiment phase i have to run many experiment in same time, how i assign each process to run each experiment? which module i should use?</p>
| 2 | 2009-11-12T07:53:16Z | 1,720,623 | <p>Have a look at the <a href="http://docs.python.org/library/multiprocessing.html" rel="nofollow">multiprocessing</a> module.</p>
| 3 | 2009-11-12T07:58:45Z | [
"python"
] |
how to run parallel job in python | 1,720,603 | <p>i do data mining project in python, during experiment phase i have to run many experiment in same time, how i assign each process to run each experiment? which module i should use?</p>
| 2 | 2009-11-12T07:53:16Z | 1,720,756 | <p>Have a look at <a href="http://stackoverflow.com/questions/203912/does-python-support-multiprocessor-multicore-programming">http://stackoverflow.com/questions/203912/does-python-support-multiprocessor-multicore-programming</a></p>
<p>Then look at <a href="http://wiki.python.org/moin/ParallelProcessing" rel="nofollo... | 3 | 2009-11-12T08:33:50Z | [
"python"
] |
Cannot write a script to "svn export" in Python | 1,720,743 | <p>I would like to write a script that will tell another server to SVN export a SVN repository.</p>
<p>This is my python script:</p>
<pre><code>import os
# svn export to crawlers
for s in ['work1.main','work2.main']:
cmd = 'ssh %s "cd /home/zes/ ; svn --force export svn+ssh://174.113.224.177/home/svn/dragon-repo... | 0 | 2009-11-12T08:28:57Z | 1,720,785 | <p>I guess that it is related to ssh. Are you using a public key to automatically connect. I think that your shell knows this key but it is not the case of python.</p>
<p>I am not sure but it's just an idea. I hope it helps</p>
| 0 | 2009-11-12T08:39:51Z | [
"python",
"linux",
"svn",
"unix"
] |
Cannot write a script to "svn export" in Python | 1,720,743 | <p>I would like to write a script that will tell another server to SVN export a SVN repository.</p>
<p>This is my python script:</p>
<pre><code>import os
# svn export to crawlers
for s in ['work1.main','work2.main']:
cmd = 'ssh %s "cd /home/zes/ ; svn --force export svn+ssh://174.113.224.177/home/svn/dragon-repo... | 0 | 2009-11-12T08:28:57Z | 1,720,791 | <p>This is a problem with SSH.</p>
<blockquote>
<p>Permission denied, please try again.</p>
</blockquote>
<p>This means that ssh can't login. Either your ssh agent doesn't have the correct key loaded, you're running the script as a different user or the environment isn't passed on correctly. Check that the variable... | 2 | 2009-11-12T08:41:20Z | [
"python",
"linux",
"svn",
"unix"
] |
Cannot write a script to "svn export" in Python | 1,720,743 | <p>I would like to write a script that will tell another server to SVN export a SVN repository.</p>
<p>This is my python script:</p>
<pre><code>import os
# svn export to crawlers
for s in ['work1.main','work2.main']:
cmd = 'ssh %s "cd /home/zes/ ; svn --force export svn+ssh://174.113.224.177/home/svn/dragon-repo... | 0 | 2009-11-12T08:28:57Z | 1,732,832 | <p>Check out the pxssh module that is part of the pyexpect project:</p>
<p><a href="https://pexpect.readthedocs.org/en/latest/api/pxssh.html" rel="nofollow">https://pexpect.readthedocs.org/en/latest/api/pxssh.html</a></p>
<p>It simplifies dealing with automating ssh-ing into machines.</p>
| 0 | 2009-11-14T00:54:19Z | [
"python",
"linux",
"svn",
"unix"
] |
Python - List of Strings to Java | 1,720,778 | <p>I'm getting a list of strings from python code and need to read it in Java. When trying to read it, i get the hashCode</p>
<blockquote>
<p><code>[Ljava.lang.Object;@7cf1bb78</code></p>
</blockquote>
<p>I want to read the values in a list. In python my return is something like</p>
<pre><code>return SUCCESS(OK, p... | 0 | 2009-11-12T08:37:58Z | 1,720,806 | <p>You already have what you want. Try <code>System.out.println(java.util.Arrays.toString(getName));</code> (the default <code>toString()</code> for an array in Java is not very useful).</p>
| 1 | 2009-11-12T08:45:19Z | [
"java",
"python"
] |
Python - List of Strings to Java | 1,720,778 | <p>I'm getting a list of strings from python code and need to read it in Java. When trying to read it, i get the hashCode</p>
<blockquote>
<p><code>[Ljava.lang.Object;@7cf1bb78</code></p>
</blockquote>
<p>I want to read the values in a list. In python my return is something like</p>
<pre><code>return SUCCESS(OK, p... | 0 | 2009-11-12T08:37:58Z | 1,720,968 | <p>The usual way to print out each item in a Java array would be something like:</p>
<pre><code>for (Object name: (Object[]) getNameList()) {
System.out.println(name);
}
</code></pre>
<p>But I suspect from your response to Aaron Digulla that (as he says) you're getting an empty array back. Try printing it out on th... | 0 | 2009-11-12T09:19:15Z | [
"java",
"python"
] |
Non-blocking file access with Twisted | 1,720,816 | <p>I'm trying to figure out if there is a defacto pattern for file access using twisted. Lots of examples I've looked at (twisted.python.log, twisted.persisted.dirdbm, twisted.web.static) actually don't seem to worry about blocking for file access. </p>
<p>It seems like there should be some obvious interface, probably... | 26 | 2009-11-12T08:47:11Z | 1,720,836 | <p>I'm not sure what you want to achieve. When you do logging, then Python will make sure (by the global interpreter log) that log messages from several threads go into the file one after the other.</p>
<p>If you're concerned about blocking IO, then the OS adds default buffers for your files (usually 4KB), and you can... | -8 | 2009-11-12T08:54:17Z | [
"python",
"twisted"
] |
Non-blocking file access with Twisted | 1,720,816 | <p>I'm trying to figure out if there is a defacto pattern for file access using twisted. Lots of examples I've looked at (twisted.python.log, twisted.persisted.dirdbm, twisted.web.static) actually don't seem to worry about blocking for file access. </p>
<p>It seems like there should be some obvious interface, probably... | 26 | 2009-11-12T08:47:11Z | 2,450,504 | <p>I think you are looking for the <a href="http://twistedmatrix.com/documents/current/api/twisted.internet.fdesc.html" rel="nofollow">fdesc module</a>. For more information on non-blocking I/O in Python, you can also watch this <a href="http://pyvideo.org/video/333/pycon-2010--demystifying-non-blocking-and-asynchr" r... | 13 | 2010-03-15T21:08:59Z | [
"python",
"twisted"
] |
Non-blocking file access with Twisted | 1,720,816 | <p>I'm trying to figure out if there is a defacto pattern for file access using twisted. Lots of examples I've looked at (twisted.python.log, twisted.persisted.dirdbm, twisted.web.static) actually don't seem to worry about blocking for file access. </p>
<p>It seems like there should be some obvious interface, probably... | 26 | 2009-11-12T08:47:11Z | 2,548,816 | <p>There is an open ticket for this in Twisted - <a href="http://twistedmatrix.com/trac/ticket/3983" rel="nofollow">#3983</a>.</p>
| 3 | 2010-03-30T21:16:37Z | [
"python",
"twisted"
] |
Non-blocking file access with Twisted | 1,720,816 | <p>I'm trying to figure out if there is a defacto pattern for file access using twisted. Lots of examples I've looked at (twisted.python.log, twisted.persisted.dirdbm, twisted.web.static) actually don't seem to worry about blocking for file access. </p>
<p>It seems like there should be some obvious interface, probably... | 26 | 2009-11-12T08:47:11Z | 33,708,936 | <p>After plenty of searching, trial, and error, I finally figured how to use <a href="http://twistedmatrix.com/documents/current/api/twisted.internet.fdesc.html" rel="nofollow"><code>fdesc</code></a>.</p>
<pre><code>from __future__ import print_function
from twisted.internet.task import react
from twisted.internet im... | 2 | 2015-11-14T13:32:07Z | [
"python",
"twisted"
] |
I just installed a Ubuntu Hardy server. In Python, I tried to import _mysql and MySQLdb | 1,720,867 | <p>But, they were unable to be found!?</p>
<p>How do I install both of them?</p>
| 1 | 2009-11-12T09:01:01Z | 1,720,881 | <p>This should do the trick.</p>
<pre><code>sudo apt-get install mysql-server
sudo apt-get install python-mysqldb
</code></pre>
| 0 | 2009-11-12T09:03:54Z | [
"python",
"linux",
"unix",
"installation"
] |
I just installed a Ubuntu Hardy server. In Python, I tried to import _mysql and MySQLdb | 1,720,867 | <p>But, they were unable to be found!?</p>
<p>How do I install both of them?</p>
| 1 | 2009-11-12T09:01:01Z | 1,720,884 | <p>I believe this should make it work:</p>
<pre><code>sudo apt-get install python-mysqldb
</code></pre>
| 0 | 2009-11-12T09:04:38Z | [
"python",
"linux",
"unix",
"installation"
] |
I just installed a Ubuntu Hardy server. In Python, I tried to import _mysql and MySQLdb | 1,720,867 | <p>But, they were unable to be found!?</p>
<p>How do I install both of them?</p>
| 1 | 2009-11-12T09:01:01Z | 1,720,904 | <p>Have you installed python-mysqldb? If not install it using <strong>apt-get install python-mysqldb</strong>. And how are you importing mysql.Is it <strong>import MySQLdb</strong>? Python is case sensitive.</p>
| 2 | 2009-11-12T09:08:25Z | [
"python",
"linux",
"unix",
"installation"
] |
Is this python code thread-safe? | 1,720,882 | <p>I am trying to make my chunk of code non-thread-safe, in order to toy with some exceptions that I want to add on later.</p>
<p>This is my python code:</p>
<pre><code>from time import sleep
from decimal import *
from threading import Lock
import random
def inc_gen(c):
"""
Increment generator
"""
wh... | 1 | 2009-11-12T09:04:09Z | 1,720,913 | <p>You have a Read-Modify-Write operation basically. If you want to ensure things go haywire, the best is to intruduce delay between the read and the write.</p>
<pre><code>def inc(self):
v = self.c
time.sleep(random.random()) # Should probably limit it to a few hundred ms
self.c = v + 1
def dec(self):
... | 0 | 2009-11-12T09:10:21Z | [
"python"
] |
Any python "compiler" that can statically link the python2x.dll dependency? | 1,720,893 | <p>It's my understanding that py2exe can only dynamically link a python2x.dll file. Are there any Python "compilers" out there that can package it all into one standalone .exe file for easier portability?</p>
<p>If so or if not, which is the best compiler z0mg!</p>
| 1 | 2009-11-12T09:07:15Z | 1,720,966 | <p>py2exe can package it all in single executable, without needing any python installation on target system, it may include python2x.dll with it, but for the end user how does it matter</p>
| 0 | 2009-11-12T09:19:12Z | [
"python",
"dll",
"compilation",
"py2exe"
] |
Any python "compiler" that can statically link the python2x.dll dependency? | 1,720,893 | <p>It's my understanding that py2exe can only dynamically link a python2x.dll file. Are there any Python "compilers" out there that can package it all into one standalone .exe file for easier portability?</p>
<p>If so or if not, which is the best compiler z0mg!</p>
| 1 | 2009-11-12T09:07:15Z | 1,721,713 | <p>From what I understand, it is possible to statically link python into an executable, but then you lose your ability to load other dynamic modules (.pyd files) like <code>os</code> and <code>zlib</code> and <code>math</code>. Unless you are able to statically compile those as well into your main program.</p>
<p>And ... | 0 | 2009-11-12T11:59:02Z | [
"python",
"dll",
"compilation",
"py2exe"
] |
Any python "compiler" that can statically link the python2x.dll dependency? | 1,720,893 | <p>It's my understanding that py2exe can only dynamically link a python2x.dll file. Are there any Python "compilers" out there that can package it all into one standalone .exe file for easier portability?</p>
<p>If so or if not, which is the best compiler z0mg!</p>
| 1 | 2009-11-12T09:07:15Z | 1,722,309 | <p><a href="http://www.pyinstaller.org/" rel="nofollow">PyInstaller</a> claims to be able to create a single-executable that's user-friendly. Perhaps that would meet your needs. I've never used it.</p>
| 1 | 2009-11-12T13:50:27Z | [
"python",
"dll",
"compilation",
"py2exe"
] |
Any python "compiler" that can statically link the python2x.dll dependency? | 1,720,893 | <p>It's my understanding that py2exe can only dynamically link a python2x.dll file. Are there any Python "compilers" out there that can package it all into one standalone .exe file for easier portability?</p>
<p>If so or if not, which is the best compiler z0mg!</p>
| 1 | 2009-11-12T09:07:15Z | 1,843,549 | <p>If you check the bottom of the py2exe <a href="http://www.py2exe.org/index.cgi/SingleFileExecutable" rel="nofollow">SingleFileExecutable wiki page</a> you'll see that it can create one-file executables. They do include the DLL inside, but you shouldn't notice that. I believe it works with a freakish hack that inte... | 2 | 2009-12-03T22:44:44Z | [
"python",
"dll",
"compilation",
"py2exe"
] |
Remove "add another" in Django admin screen | 1,721,037 | <p>Whenever I'm editing object A with a foreign key to object B, a plus option "add another" is available next to the choices of object B. How do I remove that option?</p>
<p>I configured a user without rights to add object B. The plus sign is still available, but when I click on it, it says "Permission denied". It's ... | 13 | 2009-11-12T09:35:36Z | 1,724,599 | <p>Look at <code>django.contrib.admin.options.py</code> and check out the <code>BaseModelAdmin</code> class, <code>formfield_for_dbfield</code> method.</p>
<p>You will see this:</p>
<pre><code># For non-raw_id fields, wrap the widget with a wrapper that adds
# extra HTML -- the "add other" interface -- to the end of ... | 3 | 2009-11-12T19:08:25Z | [
"python",
"django",
"django-admin"
] |
Remove "add another" in Django admin screen | 1,721,037 | <p>Whenever I'm editing object A with a foreign key to object B, a plus option "add another" is available next to the choices of object B. How do I remove that option?</p>
<p>I configured a user without rights to add object B. The plus sign is still available, but when I click on it, it says "Permission denied". It's ... | 13 | 2009-11-12T09:35:36Z | 1,726,102 | <h2>DEPRECATED ANSWER</h2>
<p>Django has since made this possible. See below.
<a href="http://stackoverflow.com/a/13159832/111375">http://stackoverflow.com/a/13159832/111375</a></p>
<hr>
<p>Have you considered instead using CSS to simply not show the button? Maybe that's a little too hacky.</p>
<p>This is unteste... | 3 | 2009-11-12T23:21:10Z | [
"python",
"django",
"django-admin"
] |
Remove "add another" in Django admin screen | 1,721,037 | <p>Whenever I'm editing object A with a foreign key to object B, a plus option "add another" is available next to the choices of object B. How do I remove that option?</p>
<p>I configured a user without rights to add object B. The plus sign is still available, but when I click on it, it says "Permission denied". It's ... | 13 | 2009-11-12T09:35:36Z | 4,115,212 | <p>django.contrib.admin.widgets.py</p>
<p>(Django Install Dir)/django/contrib/admin/widgets.py: Comment everything between Line 239 & Line 244:</p>
<pre><code> if rel_to in self.admin_site._registry: # If the related object has an admin interface:
# TODO: "id_" is hard-coded here. This should instead use ... | -1 | 2010-11-06T21:18:06Z | [
"python",
"django",
"django-admin"
] |
Remove "add another" in Django admin screen | 1,721,037 | <p>Whenever I'm editing object A with a foreign key to object B, a plus option "add another" is available next to the choices of object B. How do I remove that option?</p>
<p>I configured a user without rights to add object B. The plus sign is still available, but when I click on it, it says "Permission denied". It's ... | 13 | 2009-11-12T09:35:36Z | 13,159,832 | <p>(stop upvoting this wrong answer!!!)</p>
<p><strong>ERRATA</strong> : This answer is basically wrong, and does not answer OP's question. See below.</p>
<blockquote>
<p>(this is only applicable to inline forms, not foreign key fields as OP asked)</p>
<p>Simpler solution, no CSS hack, no editing Django codeba... | 36 | 2012-10-31T14:05:47Z | [
"python",
"django",
"django-admin"
] |
Remove "add another" in Django admin screen | 1,721,037 | <p>Whenever I'm editing object A with a foreign key to object B, a plus option "add another" is available next to the choices of object B. How do I remove that option?</p>
<p>I configured a user without rights to add object B. The plus sign is still available, but when I click on it, it says "Permission denied". It's ... | 13 | 2009-11-12T09:35:36Z | 18,437,580 | <p>N.B. Works for DJango 1.5.2 and possibly older. The <code>can_add_related</code> property <a href="https://code.djangoproject.com/ticket/9071#comment:18">appeared</a> around 2 years ago.</p>
<p>The best way I've found is to override your ModelAdmin's get_form function. In my case I wanted to force the author of a p... | 6 | 2013-08-26T06:02:35Z | [
"python",
"django",
"django-admin"
] |
Remove "add another" in Django admin screen | 1,721,037 | <p>Whenever I'm editing object A with a foreign key to object B, a plus option "add another" is available next to the choices of object B. How do I remove that option?</p>
<p>I configured a user without rights to add object B. The plus sign is still available, but when I click on it, it says "Permission denied". It's ... | 13 | 2009-11-12T09:35:36Z | 29,891,707 | <p>Though most of the solutions mentioned here work, there is another cleaner way of doing it. Probably it was introduced in a later version of Django, after the other solutions were presented. (I'm presently using Django 1.7)</p>
<p>To remove the "Add another" option,</p>
<pre><code>class ... #(Your inline class)
... | 6 | 2015-04-27T09:21:30Z | [
"python",
"django",
"django-admin"
] |
Unable to send function arguments from webapp.RequestHandler class | 1,721,156 | <p>I am getting this errorpage after uploading my application to the google app engine and calling it in the browser. </p>
<pre><code>Traceback (most recent call last):
File "/base/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 507, in __call__
handler.get(*groups)
File "/base/data/home/a... | 0 | 2009-11-12T09:56:34Z | 1,721,225 | <p>Perhaps in:</p>
<pre><code>account = db.get(src_key)
</code></pre>
<p>src_key is None?</p>
| 2 | 2009-11-12T10:10:52Z | [
"python",
"google-app-engine"
] |
Unable to send function arguments from webapp.RequestHandler class | 1,721,156 | <p>I am getting this errorpage after uploading my application to the google app engine and calling it in the browser. </p>
<pre><code>Traceback (most recent call last):
File "/base/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 507, in __call__
handler.get(*groups)
File "/base/data/home/a... | 0 | 2009-11-12T09:56:34Z | 1,722,077 | <p>You're getting this error because src_key is None, which implies this statement:</p>
<pre><code> src_key = db.GqlQuery('SELECT __key__ FROM UserDetails WHERE user_name = :uname', uname = src_username).get()
</code></pre>
<p>Is not matching any rows. Try logging the result of that statement and the username you'... | 1 | 2009-11-12T13:09:55Z | [
"python",
"google-app-engine"
] |
Howto bin series of float values into histogram in Python? | 1,721,273 | <p>I have set of value in float (always less than 0). Which I want to bin into histogram,
i,e. each bar in histogram contain range of value [0,0.150)</p>
<p>The data I have looks like this:</p>
<pre><code>0.000
0.005
0.124
0.000
0.004
0.000
0.111
0.112
</code></pre>
<p>Whith my code below I expect to get result that... | 7 | 2009-11-12T10:21:48Z | 1,721,798 | <p>The first error is:</p>
<pre><code>Traceback (most recent call last):
File "C:\foo\foo.py", line 17, in <module>
diffCounts[ str(getBin(diff)) ] += 1
TypeError: list indices must be integers
</code></pre>
<p>Why are you converting an int to a str when a str is needed? Fix that, then we get:</p>
<pre>... | 2 | 2009-11-12T12:19:45Z | [
"python",
"statistics",
"histogram",
"binning"
] |
Howto bin series of float values into histogram in Python? | 1,721,273 | <p>I have set of value in float (always less than 0). Which I want to bin into histogram,
i,e. each bar in histogram contain range of value [0,0.150)</p>
<p>The data I have looks like this:</p>
<pre><code>0.000
0.005
0.124
0.000
0.004
0.000
0.111
0.112
</code></pre>
<p>Whith my code below I expect to get result that... | 7 | 2009-11-12T10:21:48Z | 1,721,833 | <p>When possible, don't reinvent the wheel. NumPy has everything you need:</p>
<pre><code>#!/usr/bin/env python
import numpy as np
a = np.fromfile(open('file', 'r'), sep='\n')
# [ 0. 0.005 0.124 0. 0.004 0. 0.111 0.112]
# You can set arbitrary bin edges:
bins = [0, 0.150]
hist, bin_edges = np.histogr... | 11 | 2009-11-12T12:28:17Z | [
"python",
"statistics",
"histogram",
"binning"
] |
Howto bin series of float values into histogram in Python? | 1,721,273 | <p>I have set of value in float (always less than 0). Which I want to bin into histogram,
i,e. each bar in histogram contain range of value [0,0.150)</p>
<p>The data I have looks like this:</p>
<pre><code>0.000
0.005
0.124
0.000
0.004
0.000
0.111
0.112
</code></pre>
<p>Whith my code below I expect to get result that... | 7 | 2009-11-12T10:21:48Z | 13,346,599 | <pre><code>from pylab import *
data = []
inf = open('pulse_data.txt')
for line in inf:
data.append(float(line))
inf.close()
#binning
B = 50
minv = min(data)
maxv = max(data)
bincounts = []
for i in range(B+1):
bincounts.append(0)
for d in data:
b = int((d - minv) / (maxv - minv) * B)
bincounts[b] += 1
#... | 3 | 2012-11-12T15:33:31Z | [
"python",
"statistics",
"histogram",
"binning"
] |
How can I measure the execution time of a for loop? | 1,721,351 | <p>I want to measure the execution time of <strong>for loops</strong> on various platforms like php, c, python, Java, javascript... How can i measure it?</p>
<p>I know these platforms so i am talking about these:</p>
<pre><code> for (i = 0; i < 1000000; i++)
{
}
</code></pre>
<p>I don't want to measure anythin... | 1 | 2009-11-12T10:36:49Z | 1,721,377 | <p>in php: (<a href="http://www.phpsources.org/scripts139-PHP.htm" rel="nofollow">code timer</a>)</p>
<pre><code>$timer = new timer();
$timer->start();
for(i=0;i<1000000;i++)
{
}
$timer->stop();
echo $timer->getTime();
</code></pre>
| 0 | 2009-11-12T10:42:57Z | [
"java",
"php",
"c++",
"python",
"c"
] |
How can I measure the execution time of a for loop? | 1,721,351 | <p>I want to measure the execution time of <strong>for loops</strong> on various platforms like php, c, python, Java, javascript... How can i measure it?</p>
<p>I know these platforms so i am talking about these:</p>
<pre><code> for (i = 0; i < 1000000; i++)
{
}
</code></pre>
<p>I don't want to measure anythin... | 1 | 2009-11-12T10:36:49Z | 1,721,382 | <p>I asked the same question a while back that was <a href="http://stackoverflow.com/questions/483164/looking-for-benchmarking-code-snippet-c">specifically for the c++ language</a>.
Heres the answer I ended up using:</p>
<pre><code>#include <omp.h>
// Starting the time measurement
double start = omp_get_wtime()... | 0 | 2009-11-12T10:44:18Z | [
"java",
"php",
"c++",
"python",
"c"
] |
How can I measure the execution time of a for loop? | 1,721,351 | <p>I want to measure the execution time of <strong>for loops</strong> on various platforms like php, c, python, Java, javascript... How can i measure it?</p>
<p>I know these platforms so i am talking about these:</p>
<pre><code> for (i = 0; i < 1000000; i++)
{
}
</code></pre>
<p>I don't want to measure anythin... | 1 | 2009-11-12T10:36:49Z | 1,721,390 | <p>Other version in PHP that doesn't require any extra stuff:</p>
<pre><code>$start = microtime(true);
for (...) {
....
}
$end = microtime(true);
echo ($end - $start).' seconds';
</code></pre>
| 1 | 2009-11-12T10:46:34Z | [
"java",
"php",
"c++",
"python",
"c"
] |
How can I measure the execution time of a for loop? | 1,721,351 | <p>I want to measure the execution time of <strong>for loops</strong> on various platforms like php, c, python, Java, javascript... How can i measure it?</p>
<p>I know these platforms so i am talking about these:</p>
<pre><code> for (i = 0; i < 1000000; i++)
{
}
</code></pre>
<p>I don't want to measure anythin... | 1 | 2009-11-12T10:36:49Z | 1,721,397 | <p>If you're using Python, you can use a module specifically built for timing things. It's called Timeit.</p>
<p>Here are a couple of references I found (just Googled it):</p>
<ol>
<li><a href="http://www.diveintopython.org/performance%5Ftuning/timeit.html" rel="nofollow">Dive Into Python: Using the Timeit
Module</a>... | 1 | 2009-11-12T10:49:08Z | [
"java",
"php",
"c++",
"python",
"c"
] |
How can I measure the execution time of a for loop? | 1,721,351 | <p>I want to measure the execution time of <strong>for loops</strong> on various platforms like php, c, python, Java, javascript... How can i measure it?</p>
<p>I know these platforms so i am talking about these:</p>
<pre><code> for (i = 0; i < 1000000; i++)
{
}
</code></pre>
<p>I don't want to measure anythin... | 1 | 2009-11-12T10:36:49Z | 1,721,406 | <p>For compiled languages such as C and C++, make sure that your compiler flags are set such that the loop isn't optimized away. With optimization switched on I would expect most compilers to detect that nothing is going on in the loop and optimize it away.</p>
| 1 | 2009-11-12T10:51:37Z | [
"java",
"php",
"c++",
"python",
"c"
] |
How can I measure the execution time of a for loop? | 1,721,351 | <p>I want to measure the execution time of <strong>for loops</strong> on various platforms like php, c, python, Java, javascript... How can i measure it?</p>
<p>I know these platforms so i am talking about these:</p>
<pre><code> for (i = 0; i < 1000000; i++)
{
}
</code></pre>
<p>I don't want to measure anythin... | 1 | 2009-11-12T10:36:49Z | 1,721,409 | <p>Although an answer has been given for C++, it looks from your description ("[You] don't want to measure anything within the loop") like you're trying to measure the time which it takes a program to iterate over an empty loop.</p>
<p>Please take care here: not only will it take varying times from different platforms... | 5 | 2009-11-12T10:51:55Z | [
"java",
"php",
"c++",
"python",
"c"
] |
How can I measure the execution time of a for loop? | 1,721,351 | <p>I want to measure the execution time of <strong>for loops</strong> on various platforms like php, c, python, Java, javascript... How can i measure it?</p>
<p>I know these platforms so i am talking about these:</p>
<pre><code> for (i = 0; i < 1000000; i++)
{
}
</code></pre>
<p>I don't want to measure anythin... | 1 | 2009-11-12T10:36:49Z | 1,721,460 | <p>javascript</p>
<pre><code>start = new Date;
for(var i = 0; i < 1000000; i++) {}
time = new Date - start;
</code></pre>
| 2 | 2009-11-12T11:03:47Z | [
"java",
"php",
"c++",
"python",
"c"
] |
How can I measure the execution time of a for loop? | 1,721,351 | <p>I want to measure the execution time of <strong>for loops</strong> on various platforms like php, c, python, Java, javascript... How can i measure it?</p>
<p>I know these platforms so i am talking about these:</p>
<pre><code> for (i = 0; i < 1000000; i++)
{
}
</code></pre>
<p>I don't want to measure anythin... | 1 | 2009-11-12T10:36:49Z | 1,721,526 | <p>Note that it also depends on what exactly you want to achieve: do you care about the time your program waits due to it being preempted by the system scheduler? All the solutions above take actual time elapsed into consideration, but that also involves the time when other processes run instead of your own.</p>
<p>If... | 2 | 2009-11-12T11:18:09Z | [
"java",
"php",
"c++",
"python",
"c"
] |
How can I measure the execution time of a for loop? | 1,721,351 | <p>I want to measure the execution time of <strong>for loops</strong> on various platforms like php, c, python, Java, javascript... How can i measure it?</p>
<p>I know these platforms so i am talking about these:</p>
<pre><code> for (i = 0; i < 1000000; i++)
{
}
</code></pre>
<p>I don't want to measure anythin... | 1 | 2009-11-12T10:36:49Z | 1,721,799 | <p>The right way to do it in python is to run timeit from the command line:</p>
<pre><code>$ python -m timeit "for i in xrange(100): pass"
100000 loops, best of 3: 2.5 usec per loop
</code></pre>
| 2 | 2009-11-12T12:19:47Z | [
"java",
"php",
"c++",
"python",
"c"
] |
How can I measure the execution time of a for loop? | 1,721,351 | <p>I want to measure the execution time of <strong>for loops</strong> on various platforms like php, c, python, Java, javascript... How can i measure it?</p>
<p>I know these platforms so i am talking about these:</p>
<pre><code> for (i = 0; i < 1000000; i++)
{
}
</code></pre>
<p>I don't want to measure anythin... | 1 | 2009-11-12T10:36:49Z | 1,721,891 | <p>The result wont make sense in an empty loop, sine most compilers will optimize it at compiling time, before the runtime.</p>
<p>To compare languages speed, you will need a real algorithm, like "Merge Sort", "Binary Search" or maybe "Dijkstra" if you want something complicated.
Implement the same algorithm in all la... | 0 | 2009-11-12T12:35:38Z | [
"java",
"php",
"c++",
"python",
"c"
] |
How can I measure the execution time of a for loop? | 1,721,351 | <p>I want to measure the execution time of <strong>for loops</strong> on various platforms like php, c, python, Java, javascript... How can i measure it?</p>
<p>I know these platforms so i am talking about these:</p>
<pre><code> for (i = 0; i < 1000000; i++)
{
}
</code></pre>
<p>I don't want to measure anythin... | 1 | 2009-11-12T10:36:49Z | 1,721,928 | <p>To the point: just get the current time <em>before</em> doing something (this is the <strong>start time</strong>) and get the current time <em>after</em> doing something (this is the <strong>end time</strong>) and then just do the primary school math to get the elapsed time. Every API provides ways to get the curren... | 0 | 2009-11-12T12:41:18Z | [
"java",
"php",
"c++",
"python",
"c"
] |
How can I measure the execution time of a for loop? | 1,721,351 | <p>I want to measure the execution time of <strong>for loops</strong> on various platforms like php, c, python, Java, javascript... How can i measure it?</p>
<p>I know these platforms so i am talking about these:</p>
<pre><code> for (i = 0; i < 1000000; i++)
{
}
</code></pre>
<p>I don't want to measure anythin... | 1 | 2009-11-12T10:36:49Z | 1,722,376 | <p>For Java, both <a href="http://commons.apache.org/lang/" rel="nofollow">Apache Commons Lang</a> and the <a href="http://springframework.org/" rel="nofollow">Spring Framework</a> have <code>StopWatch</code> (see the Java doc for Apache's <a href="http://commons.apache.org/lang/api-release/org/apache/commons/lang/time... | 0 | 2009-11-12T14:01:22Z | [
"java",
"php",
"c++",
"python",
"c"
] |
Will python.subprocess(cppBinaryExe) compromise cppBinaryExe's performance? | 1,721,530 | <p>i am quite new to python.subprocess()</p>
<p>if i folk a new process from python, will the execution speed of this new process be compromised?</p>
<p>imagine that i have the </p>
<pre><code>#python
import subprocess
subprocess.call( MyBinary )
</code></pre>
<p>basically, is there any difference between </p>
<p... | 1 | 2009-11-12T11:18:47Z | 1,721,538 | <p>No. A separate process is a separate process. It competes for OS resources with all other processes "fairly".</p>
<p>Your python process that simply does <code>subprocess.call</code> is a process, and does consume some system resources. But relatively few, since it will be waiting for a system call to finish. I... | 3 | 2009-11-12T11:21:01Z | [
"python",
"linux"
] |
Will python.subprocess(cppBinaryExe) compromise cppBinaryExe's performance? | 1,721,530 | <p>i am quite new to python.subprocess()</p>
<p>if i folk a new process from python, will the execution speed of this new process be compromised?</p>
<p>imagine that i have the </p>
<pre><code>#python
import subprocess
subprocess.call( MyBinary )
</code></pre>
<p>basically, is there any difference between </p>
<p... | 1 | 2009-11-12T11:18:47Z | 1,721,539 | <p>No, the process runs just as if started by any other means.</p>
| 0 | 2009-11-12T11:21:11Z | [
"python",
"linux"
] |
Will python.subprocess(cppBinaryExe) compromise cppBinaryExe's performance? | 1,721,530 | <p>i am quite new to python.subprocess()</p>
<p>if i folk a new process from python, will the execution speed of this new process be compromised?</p>
<p>imagine that i have the </p>
<pre><code>#python
import subprocess
subprocess.call( MyBinary )
</code></pre>
<p>basically, is there any difference between </p>
<p... | 1 | 2009-11-12T11:18:47Z | 1,721,555 | <p>Apart from having to actually run the python interpreter, no. So your last example will take some slight time before <code>MyBinary</code> to parse and run the python program and some slight time after it completes to terminate the python program. And the python program will be an existing process which takes up a... | 2 | 2009-11-12T11:24:20Z | [
"python",
"linux"
] |
Is there any "remote console" for twisted server? | 1,721,699 | <p>I am developing a twisted server. I need to control the memory usage. It is not a good idea to modify code, insert some memory logging command and restart the server. I think it is better to use a "remote console", so that I can type heapy command and see the response from the server directly. All I need is a remote... | 5 | 2009-11-12T11:55:01Z | 1,721,715 | <p>Take a look at <code>twisted.manhole</code></p>
| 6 | 2009-11-12T11:59:49Z | [
"python",
"console",
"twisted"
] |
Is there any "remote console" for twisted server? | 1,721,699 | <p>I am developing a twisted server. I need to control the memory usage. It is not a good idea to modify code, insert some memory logging command and restart the server. I think it is better to use a "remote console", so that I can type heapy command and see the response from the server directly. All I need is a remote... | 5 | 2009-11-12T11:55:01Z | 1,721,768 | <p><code>twisted.manhole.telnet</code> uses the deprecated module <code>twisted.protocols.telnet</code>. It is recommended to use <code>twisted.conch.manhole</code> instead.</p>
<p>Here are some tutorials of how to use it:</p>
<ul>
<li><a href="http://twistedmatrix.com/projects/conch/documentation/howto/conch%5Fclien... | 13 | 2009-11-12T12:11:46Z | [
"python",
"console",
"twisted"
] |
Python dictionary simple way to add a new key value pair | 1,721,795 | <p>Say you have,</p>
<pre><code>foo = 'bar'
d = {'a-key':'a-value'}
</code></pre>
<p>And you want</p>
<pre><code>d = {'a-key':'a-value','foo':'bar'}
e = {'foo':foo}
</code></pre>
<p>I know you can do,</p>
<pre><code>d['foo'] = foo
#Either of the following for e
e = {'foo':foo}
e = dict(foo=foo)
</code></pre>
<p>... | 1 | 2009-11-12T12:18:56Z | 1,721,828 | <p>You can use:</p>
<pre><code>name = 'foo'
d[name] = vars[name]
</code></pre>
<p>I don't see the difference between your <code>d</code> and <code>e</code> cases: both set 'foo' to the value of foo. </p>
<p>It gets trickier if you want to bury this in a function:</p>
<pre><code>def add_variable(d, name):
# bla... | 2 | 2009-11-12T12:26:18Z | [
"python",
"dictionary"
] |
Python dictionary simple way to add a new key value pair | 1,721,795 | <p>Say you have,</p>
<pre><code>foo = 'bar'
d = {'a-key':'a-value'}
</code></pre>
<p>And you want</p>
<pre><code>d = {'a-key':'a-value','foo':'bar'}
e = {'foo':foo}
</code></pre>
<p>I know you can do,</p>
<pre><code>d['foo'] = foo
#Either of the following for e
e = {'foo':foo}
e = dict(foo=foo)
</code></pre>
<p>... | 1 | 2009-11-12T12:18:56Z | 1,721,855 | <p>you can do something like this</p>
<pre><code>def add_dry_foo(d, namespace, fooName):
d[fooName] = namespace[fooName]
foo = 'oh-foo'
d = {}
add_dry_foo(d, locals(), 'foo')
print d
</code></pre>
| 4 | 2009-11-12T12:31:00Z | [
"python",
"dictionary"
] |
Python dictionary simple way to add a new key value pair | 1,721,795 | <p>Say you have,</p>
<pre><code>foo = 'bar'
d = {'a-key':'a-value'}
</code></pre>
<p>And you want</p>
<pre><code>d = {'a-key':'a-value','foo':'bar'}
e = {'foo':foo}
</code></pre>
<p>I know you can do,</p>
<pre><code>d['foo'] = foo
#Either of the following for e
e = {'foo':foo}
e = dict(foo=foo)
</code></pre>
<p>... | 1 | 2009-11-12T12:18:56Z | 1,721,870 | <p>You could use eval, although I'm not sure that I'd recommend it.</p>
<pre><code>>>> d = dict()
>>> foo = 'wibble'
>>> def add(d, name):
d[name] = eval(name)
>>> add(d, 'foo')
>>> d
{'foo': 'wibble'}
</code></pre>
<p><strong>Edit:</strong>
I should point out wh... | 0 | 2009-11-12T12:32:23Z | [
"python",
"dictionary"
] |
Python dictionary simple way to add a new key value pair | 1,721,795 | <p>Say you have,</p>
<pre><code>foo = 'bar'
d = {'a-key':'a-value'}
</code></pre>
<p>And you want</p>
<pre><code>d = {'a-key':'a-value','foo':'bar'}
e = {'foo':foo}
</code></pre>
<p>I know you can do,</p>
<pre><code>d['foo'] = foo
#Either of the following for e
e = {'foo':foo}
e = dict(foo=foo)
</code></pre>
<p>... | 1 | 2009-11-12T12:18:56Z | 1,721,909 | <p>Actutally using <code>foo</code> twice is remarkably common in python programs. It is used extensively for passing on arguments eg</p>
<pre><code>def f(foo, bar):
g(foo=foo)
</code></pre>
<p>Which is a specialised case of the dictionary manipulations in your question.</p>
<p>I don't think there is a way of a... | 2 | 2009-11-12T12:38:36Z | [
"python",
"dictionary"
] |
Python dictionary simple way to add a new key value pair | 1,721,795 | <p>Say you have,</p>
<pre><code>foo = 'bar'
d = {'a-key':'a-value'}
</code></pre>
<p>And you want</p>
<pre><code>d = {'a-key':'a-value','foo':'bar'}
e = {'foo':foo}
</code></pre>
<p>I know you can do,</p>
<pre><code>d['foo'] = foo
#Either of the following for e
e = {'foo':foo}
e = dict(foo=foo)
</code></pre>
<p>... | 1 | 2009-11-12T12:18:56Z | 1,722,906 | <p>To add all the local variables to a dict you can do:</p>
<pre><code>d.update(locals())
</code></pre>
<p>The same works for function calls:</p>
<pre><code>func(**locals())
</code></pre>
<p>Note that depending on where you are <code>locals()</code> might of course contain stuff that should not end up in the dict. ... | 1 | 2009-11-12T15:13:31Z | [
"python",
"dictionary"
] |
Python dictionary simple way to add a new key value pair | 1,721,795 | <p>Say you have,</p>
<pre><code>foo = 'bar'
d = {'a-key':'a-value'}
</code></pre>
<p>And you want</p>
<pre><code>d = {'a-key':'a-value','foo':'bar'}
e = {'foo':foo}
</code></pre>
<p>I know you can do,</p>
<pre><code>d['foo'] = foo
#Either of the following for e
e = {'foo':foo}
e = dict(foo=foo)
</code></pre>
<p>... | 1 | 2009-11-12T12:18:56Z | 1,722,989 | <p>If you don't want to pass all of <code>locals()</code> (which may be a security risk if you don't fully trust the function you're sending the data too), a one-line answer could be this:</p>
<p><code>dict([ (var, locals()[var]) for var in ['foo', 'bar'] ])</code></p>
<p>or in Python 3.0 this would become possible:<... | 1 | 2009-11-12T15:22:12Z | [
"python",
"dictionary"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.