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
accurately measure time python function takes
1,685,221
<p>I need to measure the time certain parts of my program take (not for debugging but as a feature in the output). Accuracy is important because the total time will be a fraction of a second.</p> <p>I was going to use the <a href="http://docs.python.org/library/time.html">time module</a> when I came across <a href="ht...
37
2009-11-06T03:25:04Z
30,035,892
<p>I was annoyed too by the awful interface of timeit so i made a library for this, check it out its trivial to use </p> <pre><code> from pythonbenchmark import compare, measure import time a,b,c,d,e = 10,10,10,10,10 something = [a,b,c,d,e] @measure def myFunction(something): time.sleep(0.4) myFunction(input) <...
2
2015-05-04T17:10:34Z
[ "python", "time", "profiling", "timeit" ]
Transactions behaviour when request times out. [google app engine]
1,685,329
<p>Google app engine has this useful little function in its db class, </p> <pre><code>db.run_in_transaction() </code></pre> <p>Which is suppose to garentee that your method will be rolled back if an exception is raised. "<em><a href="http://code.google.com/appengine/docs/python/datastore/functions.html#run%5Fin%5Ftra...
0
2009-11-06T04:02:29Z
1,685,512
<p>Yes, the timeout raises an exception, so that also will mean a rollback.</p>
2
2009-11-06T05:04:02Z
[ "python", "google-app-engine" ]
Why we should perfer to store the serialized data not the raw code to DB?
1,685,330
<p>If we have some code(a data structure) which should be stored in DB, someone always suggests us to store the serialized data not the raw code string.</p> <p>So I'm not so sure why we should prefer the serialized data.</p> <p>Give a simple instance(in python):</p> <p>we've got a field which will store a dict of py...
2
2009-11-06T04:03:15Z
1,685,354
<p>There's always a danger in exec that someone will somehow pass in a string with some nasty code. It might never be the case in your application but in general, it's a big problem, and using built-in serialization avoids it.</p> <p>Another reason for using built-in serialization is that it makes it obvious what you'...
1
2009-11-06T04:12:07Z
[ "python", "database", "serialization" ]
Why we should perfer to store the serialized data not the raw code to DB?
1,685,330
<p>If we have some code(a data structure) which should be stored in DB, someone always suggests us to store the serialized data not the raw code string.</p> <p>So I'm not so sure why we should prefer the serialized data.</p> <p>Give a simple instance(in python):</p> <p>we've got a field which will store a dict of py...
2
2009-11-06T04:03:15Z
1,685,377
<p>Both storing as a string and using pickle are serialization strategies. Pickle is more flexible in what it can store and can be more compact. Both strategies, eval (which is what you would use over exec in this instance) and pickle.loads are insecure—both of these can run arbitrary Python code.</p> <p>Better woul...
3
2009-11-06T04:19:12Z
[ "python", "database", "serialization" ]
Why we should perfer to store the serialized data not the raw code to DB?
1,685,330
<p>If we have some code(a data structure) which should be stored in DB, someone always suggests us to store the serialized data not the raw code string.</p> <p>So I'm not so sure why we should prefer the serialized data.</p> <p>Give a simple instance(in python):</p> <p>we've got a field which will store a dict of py...
2
2009-11-06T04:03:15Z
1,685,387
<p>Firstly fetch and exec will leave your application vulnerable to code injection. If someone entered "System(rm -r /);" in your name field you would lose most of your files on a *nix system when you read in the data.</p> <p>The second reason is portability and upgradability. "pickled" objects will work on any python...
0
2009-11-06T04:21:42Z
[ "python", "database", "serialization" ]
Why we should perfer to store the serialized data not the raw code to DB?
1,685,330
<p>If we have some code(a data structure) which should be stored in DB, someone always suggests us to store the serialized data not the raw code string.</p> <p>So I'm not so sure why we should prefer the serialized data.</p> <p>Give a simple instance(in python):</p> <p>we've got a field which will store a dict of py...
2
2009-11-06T04:03:15Z
1,685,445
<p>I've preferred using a standard serialization format like JSON for storing this kind of data in the database. It makes it possible for consumers of the data to be written in other languages than python, it's basically human readable, and it's more easily query-able with SQL than pickled objects.</p>
3
2009-11-06T04:37:10Z
[ "python", "database", "serialization" ]
Why we should perfer to store the serialized data not the raw code to DB?
1,685,330
<p>If we have some code(a data structure) which should be stored in DB, someone always suggests us to store the serialized data not the raw code string.</p> <p>So I'm not so sure why we should prefer the serialized data.</p> <p>Give a simple instance(in python):</p> <p>we've got a field which will store a dict of py...
2
2009-11-06T04:03:15Z
1,685,484
<p>If I had to choose between serializing the data into something like JSON or storing a pickled data structure, I'd choose the JSON option every time. Other than the security issues everyone else is mentioning, portability is the biggest reason to not store a native python object in the database. There may be a requ...
3
2009-11-06T04:53:28Z
[ "python", "database", "serialization" ]
Why we should perfer to store the serialized data not the raw code to DB?
1,685,330
<p>If we have some code(a data structure) which should be stored in DB, someone always suggests us to store the serialized data not the raw code string.</p> <p>So I'm not so sure why we should prefer the serialized data.</p> <p>Give a simple instance(in python):</p> <p>we've got a field which will store a dict of py...
2
2009-11-06T04:03:15Z
1,685,485
<p>The question is what does serialization gain you? I bet the people recommending that you store the serialized data think you will save time because you don't need to mess around with SQL queries to construct Python objects. But there are some significant trade offs in storing you data as serialized blobs, such as:<...
2
2009-11-06T04:53:30Z
[ "python", "database", "serialization" ]
Why we should perfer to store the serialized data not the raw code to DB?
1,685,330
<p>If we have some code(a data structure) which should be stored in DB, someone always suggests us to store the serialized data not the raw code string.</p> <p>So I'm not so sure why we should prefer the serialized data.</p> <p>Give a simple instance(in python):</p> <p>we've got a field which will store a dict of py...
2
2009-11-06T04:03:15Z
1,685,493
<blockquote> <p>Or we can store the dict string directly to DB without serializing.</p> </blockquote> <p>There is no such thing as "the dict string". There are many ways to serialize a dict into a string; you may be thinking of <code>repr</code>, possibly as <code>eval</code> as the way to get the dict back (you ...
10
2009-11-06T04:58:19Z
[ "python", "database", "serialization" ]
Why we should perfer to store the serialized data not the raw code to DB?
1,685,330
<p>If we have some code(a data structure) which should be stored in DB, someone always suggests us to store the serialized data not the raw code string.</p> <p>So I'm not so sure why we should prefer the serialized data.</p> <p>Give a simple instance(in python):</p> <p>we've got a field which will store a dict of py...
2
2009-11-06T04:03:15Z
1,686,017
<p><strong>Serialization means less worrying.</strong> When you marshall your data using some known serialization — Pickle, JSON, Google's Protocol Buffers — you can trust that the data you retrieve later is the data you stored earlier.</p> <p><strong>Limit capability.</strong> If you're storing static data, why...
0
2009-11-06T07:36:17Z
[ "python", "database", "serialization" ]
Why we should perfer to store the serialized data not the raw code to DB?
1,685,330
<p>If we have some code(a data structure) which should be stored in DB, someone always suggests us to store the serialized data not the raw code string.</p> <p>So I'm not so sure why we should prefer the serialized data.</p> <p>Give a simple instance(in python):</p> <p>we've got a field which will store a dict of py...
2
2009-11-06T04:03:15Z
1,690,498
<p>If there is any possibility of manipulating this data on DB or creating reports from it; I would seriously consider unpacking it onto a table. A simple table with <code>name</code>, <code>key</code> and <code>value</code> columns would give you all the power of your relational database. Depending on edits it might e...
0
2009-11-06T21:14:44Z
[ "python", "database", "serialization" ]
Possible to use more than one argument on __getitem__?
1,685,389
<p>I am trying to use</p> <pre><code>__getitem__(self, x, y): </code></pre> <p>on my Matrix class, but it seems to me it doesn't work (I still don't know very well to use python). I'm calling it like this:</p> <pre><code>print matrix[0,0] </code></pre> <p>Is it possible at all to use more than one argument? Thanks....
12
2009-11-06T04:21:49Z
1,685,407
<p>No, <code>__getitem__</code> just takes one argument (in addition to <code>self</code>). In the case of <code>matrix[0, 0]</code>, the argument is the tuple <code>(0, 0)</code>. </p>
4
2009-11-06T04:25:56Z
[ "python" ]
Possible to use more than one argument on __getitem__?
1,685,389
<p>I am trying to use</p> <pre><code>__getitem__(self, x, y): </code></pre> <p>on my Matrix class, but it seems to me it doesn't work (I still don't know very well to use python). I'm calling it like this:</p> <pre><code>print matrix[0,0] </code></pre> <p>Is it possible at all to use more than one argument? Thanks....
12
2009-11-06T04:21:49Z
1,685,412
<p><code>__getitem__</code> only accepts one argument (other than self), so you get passed a tuple.</p> <p>You can do this:</p> <pre><code>class matrix: def __getitem__(self, pos): x,y = pos return "fetching %s, %s" % (x, y) m = matrix() print m[1,2] </code></pre> <p>outputs</p> <pre><code>fetc...
27
2009-11-06T04:27:31Z
[ "python" ]
Possible to use more than one argument on __getitem__?
1,685,389
<p>I am trying to use</p> <pre><code>__getitem__(self, x, y): </code></pre> <p>on my Matrix class, but it seems to me it doesn't work (I still don't know very well to use python). I'm calling it like this:</p> <pre><code>print matrix[0,0] </code></pre> <p>Is it possible at all to use more than one argument? Thanks....
12
2009-11-06T04:21:49Z
1,685,450
<p>Indeed, when you execute <code>bla[x,y]</code>, you're calling <code>type(bla).__getitem__(bla, (x, y))</code> -- Python automatically forms the tuple for you and passes it on to <code>__getitem__</code> as the second argument (the first one being its <code>self</code>). There's no good way<sup>[1]</sup> to express...
19
2009-11-06T04:37:41Z
[ "python" ]
how to write regex for below format using python
1,685,558
<p>I want to validate below data using regex and python.<br> Below is the dump of the data which Can be stored in string variable</p> <pre> Start 0 .......... group=..... name=...... number=.... end=(digits) Start 1 .......... group=..... name=...... number=.... end=(digits) Start 2 .......... group=..... name=.......
0
2009-11-06T05:15:29Z
1,685,597
<p>You could use <code>r'(Start \d+.*?group=.*?name=.*?number=.*?end=\d+)*'</code>.</p>
1
2009-11-06T05:23:45Z
[ "python" ]
How to remove extended ascii using python?
1,685,681
<p>In trying to fix up a PML (Palm Markup Language) file, it appears as if my test file has non-ASCII characters which is causing MakeBook to complain. The solution would be to strip out all the non-ASCII chars in the PML.</p> <p>So in attempting to fix this in python, I have</p> <pre><code>import unicodedata, filein...
5
2009-11-06T05:54:07Z
1,685,713
<p>When reading from a file in Python you're getting byte strings, aka "str" in Python 2.x and earlier. You need to convert these to the "unicode" type using the <code>decode</code> method. eg:</p> <pre><code>line = line.decode('latin1') </code></pre> <p>Replace 'latin1' with the correct encoding.</p>
0
2009-11-06T06:04:09Z
[ "python", "ascii", "extended-ascii" ]
How to remove extended ascii using python?
1,685,681
<p>In trying to fix up a PML (Palm Markup Language) file, it appears as if my test file has non-ASCII characters which is causing MakeBook to complain. The solution would be to strip out all the non-ASCII chars in the PML.</p> <p>So in attempting to fix this in python, I have</p> <pre><code>import unicodedata, filein...
5
2009-11-06T05:54:07Z
1,685,726
<p>Try <code>print line.decode('iso-8859-1').encode('ascii', 'ignore')</code> -- that should be much closer to what you want.</p>
5
2009-11-06T06:08:21Z
[ "python", "ascii", "extended-ascii" ]
How to remove extended ascii using python?
1,685,681
<p>In trying to fix up a PML (Palm Markup Language) file, it appears as if my test file has non-ASCII characters which is causing MakeBook to complain. The solution would be to strip out all the non-ASCII chars in the PML.</p> <p>So in attempting to fix this in python, I have</p> <pre><code>import unicodedata, filein...
5
2009-11-06T05:54:07Z
1,685,757
<p>You would like to treat <code>line</code> as ASCII-encoded data, so the answer is to decode it to text using the ascii codec:</p> <p><code>line.decode('ascii')</code></p> <p>This will raise errors for data that is not in fact ASCII-encoded. This is how to ignore those errors:</p> <p><code>line.decode('ascii', 'i...
5
2009-11-06T06:17:55Z
[ "python", "ascii", "extended-ascii" ]
How to remove extended ascii using python?
1,685,681
<p>In trying to fix up a PML (Palm Markup Language) file, it appears as if my test file has non-ASCII characters which is causing MakeBook to complain. The solution would be to strip out all the non-ASCII chars in the PML.</p> <p>So in attempting to fix this in python, I have</p> <pre><code>import unicodedata, filein...
5
2009-11-06T05:54:07Z
1,686,889
<p>To drop non-ASCII characters use <code>line.decode(your_file_encoding).encode('ascii', 'ignore')</code>. But probably you'd better use PLM escape sequences for them:</p> <pre><code>import re def escape_unicode(m): return '\\U%04x' % ord(m.group()) non_ascii = re.compile(u'[\x80-\uFFFF]', re.U) line = u'\\B1a...
2
2009-11-06T11:02:05Z
[ "python", "ascii", "extended-ascii" ]
How do I copy local Google App Engine Python datastore to local Google App Engine Java datastore?
1,685,810
<p>I have around 4000 entities that I need to insert into a Java App Engine datastore. As I understand it, only the Python version of App Engine currently has tools to upload data from a CSV file to a datastore. So, what I have done thus far is follow the instructions at <a href="http://code.google.com/appengine/docs...
1
2009-11-06T06:31:55Z
1,686,462
<p>The Python and Java local datastore files are not compatible. You can't move directly from one to the other. remote_api support is forthcoming for Java, but until then, you will have to implement your own data loading for the local Java datastore (you can still use the Python loader for the production server).</p>
3
2009-11-06T09:30:34Z
[ "java", "python", "google-app-engine", "local", "gae-datastore" ]
How do I copy local Google App Engine Python datastore to local Google App Engine Java datastore?
1,685,810
<p>I have around 4000 entities that I need to insert into a Java App Engine datastore. As I understand it, only the Python version of App Engine currently has tools to upload data from a CSV file to a datastore. So, what I have done thus far is follow the instructions at <a href="http://code.google.com/appengine/docs...
1
2009-11-06T06:31:55Z
1,712,239
<p><a href="http://approcket.googlecode.com" rel="nofollow">AppRocket replication</a> I recommend and use daily</p>
1
2009-11-11T00:34:13Z
[ "java", "python", "google-app-engine", "local", "gae-datastore" ]
Auto run unit test cases in Python
1,685,885
<p>We have a python based web application along with its unit test cases. Our need is to automate the process of running unit test cases. They should run either after every checking OR after every fixed time interval. With minimal effort and time what is best tool that we can use to automate this process. We are using ...
3
2009-11-06T06:58:34Z
1,685,899
<p>You're basically looking for <a href="http://en.wikipedia.org/wiki/Continuous%5Fintegration" rel="nofollow">continuous integration</a> tools and processes (I mention the term of art because it helps you research the subject in more depth). <a href="http://agiletesting.blogspot.com/2006/02/continuous-integration-wit...
3
2009-11-06T07:03:38Z
[ "python", "unit-testing", "automation" ]
Auto run unit test cases in Python
1,685,885
<p>We have a python based web application along with its unit test cases. Our need is to automate the process of running unit test cases. They should run either after every checking OR after every fixed time interval. With minimal effort and time what is best tool that we can use to automate this process. We are using ...
3
2009-11-06T06:58:34Z
1,686,052
<p>Your goal is to identify which checkins caused tests to fail. Great intuition!</p> <p>You're using Git, so you may want to start with <a href="http://git-scm.com/docs/githooks" rel="nofollow">githooks</a>, which would allow you to create a <code>post-commit</code> script which runs the tests after a commit. If you'...
1
2009-11-06T07:46:46Z
[ "python", "unit-testing", "automation" ]
Auto run unit test cases in Python
1,685,885
<p>We have a python based web application along with its unit test cases. Our need is to automate the process of running unit test cases. They should run either after every checking OR after every fixed time interval. With minimal effort and time what is best tool that we can use to automate this process. We are using ...
3
2009-11-06T06:58:34Z
1,686,106
<p><a href="http://hudson-ci.org/" rel="nofollow">Hudson</a> is a good choice for this - I've used it with success in the past. It will monitor the git repository for changes; run the tests and report on failures. It will maintain a history of tests in your project. It has a large number of <a href="http://wiki.hudson-...
2
2009-11-06T08:04:27Z
[ "python", "unit-testing", "automation" ]
Embedding Gnash into PyGame?
1,685,969
<p>Is there a way to display flash applications using Gnash renderer (I'm not averse to Adobe's renderer but would prefer not to use it) in a PyGame application?</p>
1
2009-11-06T07:23:36Z
1,689,345
<p>Does Gnash allow drawing to an SDL_Surface? If so, Pygame has a C API that would make gluing these together easy. If not your best bet will be Pygame's <a href="http://www.pygame.org/docs/ref/image.html#pygame.image.frombuffer" rel="nofollow">frombuffer</a> command. This will interepret a raw block of data as an ima...
0
2009-11-06T18:13:27Z
[ "python", "flash", "pygame", "gnash" ]
Matrix data structure
1,686,162
<p>A simple 2 dimensional array allows swapping rows (or columns) in a matrix in O(1) time. Is there an efficient data structure that would allow swapping both rows and columns of a matrix in O(1) time?</p>
1
2009-11-06T08:18:18Z
1,686,229
<p>You have to store your matrix either as a list of rows or list of columns. Which gives either swapping of rows or swapping of columns in O(1).</p> <p>However, you can add another layer on top of it to handle column order so that you can reorder columns in O(1).</p> <p>So for every access you need to do:</p> <pre>...
3
2009-11-06T08:35:45Z
[ "python", "matrix" ]
Matrix data structure
1,686,162
<p>A simple 2 dimensional array allows swapping rows (or columns) in a matrix in O(1) time. Is there an efficient data structure that would allow swapping both rows and columns of a matrix in O(1) time?</p>
1
2009-11-06T08:18:18Z
1,686,380
<p>Maybe <a href="http://www.scipy.org/Tentative%5FNumPy%5FTutorial" rel="nofollow">numpy array</a> can help you -- it allows to access both rows and columns and it's fairly efficient (it's the basic data type for scipy)</p> <pre><code>&gt;&gt;&gt; def f(x,y): ... return 10*x+y ... &gt;&gt;&gt; b = fromfunctio...
0
2009-11-06T09:12:06Z
[ "python", "matrix" ]
wxPython: How should I organize per-widget data in the controller?
1,686,235
<p>I have a widget that displays a filesystem hierarchy for convenient browsing (basically a tree control and some associated toolbar buttons, such as "refresh"). Each of these widgets has a set of base directories for it to display (recursively). Assume that the user may instantiate as many of these widgets as they fi...
4
2009-11-06T08:37:10Z
1,731,587
<p>Based on how the MVC methodology operates, I would suggest that you go with a modification the first solution you listed:</p> <blockquote> <p>make the base directories an instance variable on the widget and have the controller manipulate it to retain state for that widget.</p> </blockquote> <p>Why? You stated th...
1
2009-11-13T20:09:47Z
[ "python", "design", "model-view-controller", "user-interface" ]
wxPython: How should I organize per-widget data in the controller?
1,686,235
<p>I have a widget that displays a filesystem hierarchy for convenient browsing (basically a tree control and some associated toolbar buttons, such as "refresh"). Each of these widgets has a set of base directories for it to display (recursively). Assume that the user may instantiate as many of these widgets as they fi...
4
2009-11-06T08:37:10Z
1,736,618
<p>The solution I've currently adopted is, "per-widget controllers." (Maybe there's an existing name for it.) It delegates to a "parent" controller for any UI-wide functionality, but exists to control the widget and associate any relevant data on a per-widget basis.</p> <p>The "per-widget controller" concept avoids pr...
0
2009-11-15T04:59:59Z
[ "python", "design", "model-view-controller", "user-interface" ]
wxPython: How should I organize per-widget data in the controller?
1,686,235
<p>I have a widget that displays a filesystem hierarchy for convenient browsing (basically a tree control and some associated toolbar buttons, such as "refresh"). Each of these widgets has a set of base directories for it to display (recursively). Assume that the user may instantiate as many of these widgets as they fi...
4
2009-11-06T08:37:10Z
1,738,316
<p>The anomaly (from the MVC viewpoint) that makes this design difficult to make MVC-conformant is that you want to display information that, by your conceptualization, "does not live in a model". There is no such thing as "information that does not live in a model" in MVC: <strong>its</strong> conceptual root is "the...
2
2009-11-15T18:14:29Z
[ "python", "design", "model-view-controller", "user-interface" ]
Django Forms not rendering ModelChoiceField's query set
1,686,292
<p>I have the following ModelForm:</p> <pre><code>class AttendanceForm(forms.ModelForm): def __init__(self, *args, **kwargs): operation_id = kwargs['operation_id'] del kwargs['operation_id'] super(AttendanceForm, self).__init__(*args, **kwargs) self.fields['deployment'].query_set = ...
0
2009-11-06T08:53:05Z
1,686,501
<p>The parameter is <code>queryset</code>, not <code>query_set</code>. See <a href="http://docs.djangoproject.com/en/dev/ref/forms/fields/#fields-which-handle-relationships" rel="nofollow">the documentation</a>.</p>
4
2009-11-06T09:39:26Z
[ "python", "django", "django-forms" ]
Problem with python soap library suds. Wsdl was not understood
1,686,570
<p>The code below throw a SAXParseException: "mismatched tag":</p> <pre><code>from suds.client import Client &lt;br&gt; url = 'http://www.didww.com/api/?wsdl' client = Client(url, cache=None) print client </code></pre> <p>Is it problem with suds, or there is some errors in wsdl?</p>
2
2009-11-06T09:59:18Z
1,686,643
<p>Have you looked at the WSDL file in a browser or XML viewer? That should answer your question as to whether the problem is in the wsdl. The exception suggests there is something up with it.</p>
1
2009-11-06T10:12:53Z
[ "python", "soap", "wsdl", "suds" ]
Problem with python soap library suds. Wsdl was not understood
1,686,570
<p>The code below throw a SAXParseException: "mismatched tag":</p> <pre><code>from suds.client import Client &lt;br&gt; url = 'http://www.didww.com/api/?wsdl' client = Client(url, cache=None) print client </code></pre> <p>Is it problem with suds, or there is some errors in wsdl?</p>
2
2009-11-06T09:59:18Z
1,686,649
<p>Seems to work for me, suds 0.3.3 (without cache option - None is not a valid option for cache in my version of suds):</p> <pre><code>In [4]: from suds.client import Client In [5]: url = 'https://xml.192.com/IDSearch.cfc?wsdl' In [6]: c = Client(url) In [7]: print c Suds ( https://fedorahosted.org/suds/ ) version:...
1
2009-11-06T10:14:28Z
[ "python", "soap", "wsdl", "suds" ]
Problem with python soap library suds. Wsdl was not understood
1,686,570
<p>The code below throw a SAXParseException: "mismatched tag":</p> <pre><code>from suds.client import Client &lt;br&gt; url = 'http://www.didww.com/api/?wsdl' client = Client(url, cache=None) print client </code></pre> <p>Is it problem with suds, or there is some errors in wsdl?</p>
2
2009-11-06T09:59:18Z
8,035,637
<p>I have tried to reproduce your problem but all works for me.</p> <p>i'm using suds 0.4</p> <p>running </p> <pre><code>from suds.client import Client client = Client('http://api.didww.com/api/index.php?wsdl', cache=None) print client </code></pre> <p>gives</p> <pre><code>Suds ( https://fedorahosted.org/suds/ )...
0
2011-11-07T11:11:27Z
[ "python", "soap", "wsdl", "suds" ]
Why does Pylons use StackedObjectProxies instead of threading.local?
1,686,768
<p>It seems like threading.local is more straightforward and more robust.</p>
2
2009-11-06T10:36:44Z
1,686,843
<p>Because <code>threading.local</code> is <em>new in Python 2.4</em>. The <code>StackedObjectProxy</code> uses threading.local if it can.</p>
1
2009-11-06T10:53:49Z
[ "python", "pylons" ]
Why does Pylons use StackedObjectProxies instead of threading.local?
1,686,768
<p>It seems like threading.local is more straightforward and more robust.</p>
2
2009-11-06T10:36:44Z
1,717,416
<p>StackedObjectProxy uses a threading.local underneath it. Pylons doesn't use plain threading.locals for 2 reasons:</p> <p>1) it'd be a more intrusive API than a proxy. E.g. request().POST.get('file') vs request.POST.get('file')</p> <p>2) StackedObjectProxys are not only thread safe, but also "request safe" -- meani...
4
2009-11-11T19:12:42Z
[ "python", "pylons" ]
Sphinx (documentation tool): set tab width in output
1,686,837
<p>How do you set tab width in HTML output of Sphinx code snippets highlighted by Pygments? By default it is the annoying 8, but I want 4. Did not find a word about this setting in Sphinx conf.py.</p>
6
2009-11-06T10:52:21Z
1,696,930
<p>You will need to write a Sphinx Extension. <a href="http://sphinx.pocoo.org/ext/appapi.html?highlight=pygments#sphinx.application.Sphinx.add%5Flexer" rel="nofollow">Add your custom Lexer</a>, and apply it with <a href="http://pygments.org/docs/filters/" rel="nofollow">VisibleWhitespaceFilter</a>.</p>
0
2009-11-08T15:49:49Z
[ "python", "python-sphinx" ]
Sphinx (documentation tool): set tab width in output
1,686,837
<p>How do you set tab width in HTML output of Sphinx code snippets highlighted by Pygments? By default it is the annoying 8, but I want 4. Did not find a word about this setting in Sphinx conf.py.</p>
6
2009-11-06T10:52:21Z
1,818,835
<p>I asked the same question on sphinx-dev group and it turns out it's a problem with Docutils which is used by Sphinx. Docutils replace all tabs with 8 spaces and currently there is no way to change that value from Sphinx.</p> <p><a href="http://groups.google.com/group/sphinx-dev/browse%5Fthread/thread/35b8071ffe9a8f...
0
2009-11-30T09:51:16Z
[ "python", "python-sphinx" ]
Sphinx (documentation tool): set tab width in output
1,686,837
<p>How do you set tab width in HTML output of Sphinx code snippets highlighted by Pygments? By default it is the annoying 8, but I want 4. Did not find a word about this setting in Sphinx conf.py.</p>
6
2009-11-06T10:52:21Z
12,699,677
<p>Add something like this to your conf.py:</p> <pre><code>import re def process_docstring(app, what, name, obj, options, lines): spaces_pat = re.compile(r"( {8})") ll = [] for l in lines: ll.append(spaces_pat.sub(" ",l)) lines[:] = ll def setup(app): app.connect('autodoc-process-docst...
2
2012-10-02T23:02:08Z
[ "python", "python-sphinx" ]
Weighted average of angles
1,686,994
<p>I want to calculate the weighted mean of a set of angles.</p> <p>In <a href="http://stackoverflow.com/questions/491738/how-do-you-calculate-the-average-of-a-set-of-angles">this Question</a>, there's an answer how to calculate the mean as shown in <a href="http://catless.ncl.ac.uk/Risks/7.44.html#subj4" rel="nofollo...
2
2009-11-06T11:23:46Z
1,687,116
<p>OK, my attemp was to just multiply the values with the weights:</p> <pre><code>def circular_mean(weights, angles): x = y = 0. for angle, weight in zip(angles, weights): x += math.cos(math.radians(angle)) * weight y += math.sin(math.radians(angle)) * weight mean = math.degrees(math.atan2...
3
2009-11-06T11:52:31Z
[ "python", "algorithm", "mean" ]
Weighted average of angles
1,686,994
<p>I want to calculate the weighted mean of a set of angles.</p> <p>In <a href="http://stackoverflow.com/questions/491738/how-do-you-calculate-the-average-of-a-set-of-angles">this Question</a>, there's an answer how to calculate the mean as shown in <a href="http://catless.ncl.ac.uk/Risks/7.44.html#subj4" rel="nofollo...
2
2009-11-06T11:23:46Z
1,687,248
<p>Depending on your application the question has different answers. As mentioned above you may need to normalize your values and you may need to have signed angles, or you may not wish to. Unless you know what the angle generating function is there may not be a unique answer.</p> <p>This was a sufficient problem for ...
1
2009-11-06T12:24:12Z
[ "python", "algorithm", "mean" ]
How to profile a Django custom management command exclusively
1,687,125
<p>I would like to profile a custom management command that is relatively CPU intensive (renders an image using PIL). When I use the following command I get all sorts of Django modules (admin, ORM etc) in my profiling results:</p> <pre><code>python -m cProfile manage.py testrender </code></pre> <p>I have removed all ...
7
2009-11-06T11:54:56Z
1,687,532
<p>If I can't find any answers. <a href="http://code.google.com/p/jrfonseca/wiki/Gprof2Dot" rel="nofollow">Gprof2Dot</a> as <a href="http://stackoverflow.com/questions/843671/profiling-in-python-who-called-the-function/843725#843725">explained here</a> can be an acceptable hack.</p> <p>It doesn't filter out modules I'...
0
2009-11-06T13:15:57Z
[ "python", "django", "profiling" ]
How to profile a Django custom management command exclusively
1,687,125
<p>I would like to profile a custom management command that is relatively CPU intensive (renders an image using PIL). When I use the following command I get all sorts of Django modules (admin, ORM etc) in my profiling results:</p> <pre><code>python -m cProfile manage.py testrender </code></pre> <p>I have removed all ...
7
2009-11-06T11:54:56Z
1,688,726
<p>Separate the PIL functionality into its own function/class in its own module, and import it from your management command. Then you can test/profile the PIL functionality independently of Django.</p>
0
2009-11-06T16:33:02Z
[ "python", "django", "profiling" ]
How to profile a Django custom management command exclusively
1,687,125
<p>I would like to profile a custom management command that is relatively CPU intensive (renders an image using PIL). When I use the following command I get all sorts of Django modules (admin, ORM etc) in my profiling results:</p> <pre><code>python -m cProfile manage.py testrender </code></pre> <p>I have removed all ...
7
2009-11-06T11:54:56Z
1,693,616
<p>I solved this problem the following way:</p> <pre><code>from cProfile import Profile from django.core.management.base import BaseCommand class Command(BaseCommand): ... def _handle(self, *args, **options): # Actual code I want to profile pass def handle(self, *args, **options): ...
9
2009-11-07T16:40:05Z
[ "python", "django", "profiling" ]
Why does str.lstrip strips an extra character?
1,687,171
<pre><code>Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; path = "/Volumes/Users" &gt;&gt;&gt; path.lstrip('/Volume') 's/Users' &gt;&gt;&gt; path.lstrip('/Volumes') 'Users...
9
2009-11-06T12:05:30Z
1,687,179
<p><code>lstrip</code> is character-based, it removes all characters from the left end that are in that string.</p> <p>To verify this, try this:</p> <pre><code>"/Volumes/Users".lstrip("semuloV/") </code></pre> <p>Since / is part of the string, it is removed.</p> <p>I suspect you need to use slicing instead:</p> <p...
22
2009-11-06T12:08:10Z
[ "python", "string" ]
Why does str.lstrip strips an extra character?
1,687,171
<pre><code>Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; path = "/Volumes/Users" &gt;&gt;&gt; path.lstrip('/Volume') 's/Users' &gt;&gt;&gt; path.lstrip('/Volumes') 'Users...
9
2009-11-06T12:05:30Z
1,687,188
<p>The argument passed to <code>lstrip</code> is taken as a set of characters!</p> <pre><code>&gt;&gt;&gt; ' spacious '.lstrip() 'spacious ' &gt;&gt;&gt; 'www.example.com'.lstrip('cmowz.') 'example.com' </code></pre> <p>See also the <a href="http://docs.python.org/library/stdtypes.html">documentation</a></p> <...
13
2009-11-06T12:09:48Z
[ "python", "string" ]
Why does str.lstrip strips an extra character?
1,687,171
<pre><code>Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; path = "/Volumes/Users" &gt;&gt;&gt; path.lstrip('/Volume') 's/Users' &gt;&gt;&gt; path.lstrip('/Volumes') 'Users...
9
2009-11-06T12:05:30Z
1,687,194
<p>lstrip doc says:</p> <pre><code>Return a copy of the string S with leading whitespace removed. If chars is given and not None, remove characters in chars instead. If chars is unicode, S will be converted to unicode before stripping </code></pre> <p>So you are removing every character that is contained in the given...
1
2009-11-06T12:10:51Z
[ "python", "string" ]
Why does str.lstrip strips an extra character?
1,687,171
<pre><code>Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; path = "/Volumes/Users" &gt;&gt;&gt; path.lstrip('/Volume') 's/Users' &gt;&gt;&gt; path.lstrip('/Volumes') 'Users...
9
2009-11-06T12:05:30Z
1,687,204
<p>Strip is character-based. If you are trying to do path manipulation you should have a look at <a href="http://docs.python.org/library/os.path.html">os.path</a></p> <pre><code>&gt;&gt;&gt; os.path.split("/Volumes/Users") ('/Volumes', 'Users') </code></pre>
17
2009-11-06T12:13:38Z
[ "python", "string" ]
Why does str.lstrip strips an extra character?
1,687,171
<pre><code>Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; path = "/Volumes/Users" &gt;&gt;&gt; path.lstrip('/Volume') 's/Users' &gt;&gt;&gt; path.lstrip('/Volumes') 'Users...
9
2009-11-06T12:05:30Z
1,697,793
<p>Here is a primitive version of lstrip (that I wrote) that might help clear things up for you:</p> <pre><code>def lstrip(s, chars): for i in range len(s): char = s[i] if not char in chars: return s[i:] else: return lstrip(s[i:], chars) </code></pre> <p>Thus, you c...
0
2009-11-08T20:18:24Z
[ "python", "string" ]
PyCrypto not fully installed on Windows XP
1,687,283
<p>I ran <code>python setup.py install</code> in a Windows XP console, and it reported as follows:</p> <pre><code>running install running build running build_py running build_ext warning: GMP library not found; Not building Crypto.PublicKey._fastmath. building 'Crypto.Random.OSRNG.winrandom' extension error: None </co...
29
2009-11-06T12:32:11Z
1,687,516
<p>On windows, it may just be easier installing PyCrypto via a prebuilt windows installer. The Voidspace site has <a href="http://www.voidspace.org.uk/python/modules.shtml#pycrypto">PyCrypto 2.1 and 2.3 installers for Python 2.2-2.7</a>.</p>
43
2009-11-06T13:12:27Z
[ "python", "windows", "pycrypto" ]
PyCrypto not fully installed on Windows XP
1,687,283
<p>I ran <code>python setup.py install</code> in a Windows XP console, and it reported as follows:</p> <pre><code>running install running build running build_py running build_ext warning: GMP library not found; Not building Crypto.PublicKey._fastmath. building 'Crypto.Random.OSRNG.winrandom' extension error: None </co...
29
2009-11-06T12:32:11Z
1,936,804
<p>You may use <a href="http://docs.activestate.com/activepython/2.7/pypm.html" rel="nofollow">PyPM</a> to install (pre-built binary package of) pycrypto:</p> <pre><code>C:&gt; pypm install pycrypto Ready to perform these actions: The following packages will be installed: pycrypto-2.0.1 Get: [pypm.activestate.com] py...
0
2009-12-20T19:55:31Z
[ "python", "windows", "pycrypto" ]
PyCrypto not fully installed on Windows XP
1,687,283
<p>I ran <code>python setup.py install</code> in a Windows XP console, and it reported as follows:</p> <pre><code>running install running build running build_py running build_ext warning: GMP library not found; Not building Crypto.PublicKey._fastmath. building 'Crypto.Random.OSRNG.winrandom' extension error: None </co...
29
2009-11-06T12:32:11Z
11,405,925
<p>For other people like me on 64 bit windows 7:</p> <p>Short version: Follow <a href="http://yorickdowne.wordpress.com/2010/12/22/compiling-pycrypto-on-win7-64/" rel="nofollow">this</a> instructions.</p> <p>Long version:</p> <p>Install VC++ 2008 SP1 Express. you can get it from <a href="http://www.microsoft.com/vis...
3
2012-07-10T02:45:20Z
[ "python", "windows", "pycrypto" ]
How do you generate random unique identifiers in a multi process and multi thread environment?
1,687,344
<p>Every solution I come up with is not thread save.</p> <pre><code>def uuid(cls,db): u = hexlify(os.urandom(8)).decode('ascii') db.execute('SELECT sid FROM sessions WHERE sid=?',(u,)) if db.fetch(): u=cls.uuid(db) else: db.execute('INSERT INTO sessions (sid) VALUES (?)',(u,)) return u </code></pre...
2
2009-11-06T12:43:23Z
1,687,367
<p>No need to call the database I'd think:</p> <pre><code>&gt;&gt;&gt; import uuid # make a UUID based on the host ID and current time &gt;&gt;&gt; uuid.uuid1() UUID('a8098c1a-f86e-11da-bd1a-00112444be1e') </code></pre> <p>From <a href="http://zesty.ca/python/uuid.html" rel="nofollow">this page</a>.</p>
1
2009-11-06T12:47:07Z
[ "python", "sql", "mod-wsgi" ]
How do you generate random unique identifiers in a multi process and multi thread environment?
1,687,344
<p>Every solution I come up with is not thread save.</p> <pre><code>def uuid(cls,db): u = hexlify(os.urandom(8)).decode('ascii') db.execute('SELECT sid FROM sessions WHERE sid=?',(u,)) if db.fetch(): u=cls.uuid(db) else: db.execute('INSERT INTO sessions (sid) VALUES (?)',(u,)) return u </code></pre...
2
2009-11-06T12:43:23Z
1,687,396
<p>If you absolutely need to verify uid against database and avoid race conditions, use transactions:</p> <pre><code>BEGIN TRANSACTION SELECT COUNT(*) FROM sessions WHERE sid=%s INSERT INTO sessions (sid,...) VALUES (%s,...) COMMIT </code></pre>
0
2009-11-06T12:50:51Z
[ "python", "sql", "mod-wsgi" ]
How do you generate random unique identifiers in a multi process and multi thread environment?
1,687,344
<p>Every solution I come up with is not thread save.</p> <pre><code>def uuid(cls,db): u = hexlify(os.urandom(8)).decode('ascii') db.execute('SELECT sid FROM sessions WHERE sid=?',(u,)) if db.fetch(): u=cls.uuid(db) else: db.execute('INSERT INTO sessions (sid) VALUES (?)',(u,)) return u </code></pre...
2
2009-11-06T12:43:23Z
1,687,398
<p>I'd start with a thread-unique ID and (somehow) concatenate that with a thread-local counter, then feed it through a cryptographic hash algorithm.</p>
1
2009-11-06T12:51:36Z
[ "python", "sql", "mod-wsgi" ]
How do you generate random unique identifiers in a multi process and multi thread environment?
1,687,344
<p>Every solution I come up with is not thread save.</p> <pre><code>def uuid(cls,db): u = hexlify(os.urandom(8)).decode('ascii') db.execute('SELECT sid FROM sessions WHERE sid=?',(u,)) if db.fetch(): u=cls.uuid(db) else: db.execute('INSERT INTO sessions (sid) VALUES (?)',(u,)) return u </code></pre...
2
2009-11-06T12:43:23Z
1,687,428
<p>If you require thread safety why not put you random number generator a function that uses a shared lock:</p> <pre><code>import threading lock = threading.Lock() def get_random_number(lock) with lock: print "This can only be done by one thread at a time" </code></pre> <p>If all the threads calling <code...
2
2009-11-06T12:56:38Z
[ "python", "sql", "mod-wsgi" ]
How do you generate random unique identifiers in a multi process and multi thread environment?
1,687,344
<p>Every solution I come up with is not thread save.</p> <pre><code>def uuid(cls,db): u = hexlify(os.urandom(8)).decode('ascii') db.execute('SELECT sid FROM sessions WHERE sid=?',(u,)) if db.fetch(): u=cls.uuid(db) else: db.execute('INSERT INTO sessions (sid) VALUES (?)',(u,)) return u </code></pre...
2
2009-11-06T12:43:23Z
1,687,731
<p>Your algorithm is OK (thread safe as far as your DB API module is safe) and probably is the best way to go. It will never give you duplicate (assuming you have PRIMARY or UNIQUE key on sid), but you have a neglectfully small chance to get <code>IntegrityError</code> exception on INSERT. But your code doesn't look go...
3
2009-11-06T13:53:49Z
[ "python", "sql", "mod-wsgi" ]
How do you generate random unique identifiers in a multi process and multi thread environment?
1,687,344
<p>Every solution I come up with is not thread save.</p> <pre><code>def uuid(cls,db): u = hexlify(os.urandom(8)).decode('ascii') db.execute('SELECT sid FROM sessions WHERE sid=?',(u,)) if db.fetch(): u=cls.uuid(db) else: db.execute('INSERT INTO sessions (sid) VALUES (?)',(u,)) return u </code></pre...
2
2009-11-06T12:43:23Z
1,688,444
<pre><code>import os, threading, Queue def idmaker(aqueue): while True: u = hexlify(os.urandom(8)).decode('ascii') aqueue.put(u) idqueue = Queue.Queue(2) t = threading.Thread(target=idmaker, args=(idqueue,)) t.daemon = True t.start() def idgetter(): return idqueue.get() </code></pre> <p>Queue is often ...
5
2009-11-06T15:50:08Z
[ "python", "sql", "mod-wsgi" ]
How do you generate random unique identifiers in a multi process and multi thread environment?
1,687,344
<p>Every solution I come up with is not thread save.</p> <pre><code>def uuid(cls,db): u = hexlify(os.urandom(8)).decode('ascii') db.execute('SELECT sid FROM sessions WHERE sid=?',(u,)) if db.fetch(): u=cls.uuid(db) else: db.execute('INSERT INTO sessions (sid) VALUES (?)',(u,)) return u </code></pre...
2
2009-11-06T12:43:23Z
1,688,983
<p>Is there not a unique piece of data in each thread? It is difficult for me to imagine two threads with exactly the same data. Though I don't discount the possibility.</p> <p>In the past when I have done things of this nature there is usually something unique about the thread. User name or client name or something o...
0
2009-11-06T17:11:53Z
[ "python", "sql", "mod-wsgi" ]
How do you generate random unique identifiers in a multi process and multi thread environment?
1,687,344
<p>Every solution I come up with is not thread save.</p> <pre><code>def uuid(cls,db): u = hexlify(os.urandom(8)).decode('ascii') db.execute('SELECT sid FROM sessions WHERE sid=?',(u,)) if db.fetch(): u=cls.uuid(db) else: db.execute('INSERT INTO sessions (sid) VALUES (?)',(u,)) return u </code></pre...
2
2009-11-06T12:43:23Z
1,692,619
<p>I'm suggesting just a small modification to the accepted answer by Denis:</p> <pre><code>for i in range(MAX_ATTEMPTS): sid = os.urandom(8).decode('hex') try: db.execute('INSERT INTO sessions (sid) VALUES (?)', (sid,)) except IntegrityError: continue break else: raise RuntimeError...
3
2009-11-07T10:08:51Z
[ "python", "sql", "mod-wsgi" ]
How do you generate random unique identifiers in a multi process and multi thread environment?
1,687,344
<p>Every solution I come up with is not thread save.</p> <pre><code>def uuid(cls,db): u = hexlify(os.urandom(8)).decode('ascii') db.execute('SELECT sid FROM sessions WHERE sid=?',(u,)) if db.fetch(): u=cls.uuid(db) else: db.execute('INSERT INTO sessions (sid) VALUES (?)',(u,)) return u </code></pre...
2
2009-11-06T12:43:23Z
1,694,534
<p>mkdtemp should be thread-safe,simple and secure :</p> <pre><code>def uuid(): import tempfile,os _tdir = tempfile.mkdtemp(prefix='uuid_') _uuid = os.path.basename(_tdir) os.rmdir(_tdir) return _uuid </code></pre>
0
2009-11-07T21:45:57Z
[ "python", "sql", "mod-wsgi" ]
Updating Python on Mac
1,687,357
<p>I wanted to update my python 2.6.1 to 3.x on mac but i was wondering if its possible to do it using terminal or i have to download the installer from python website? </p> <p>The reason why i am asking this question is because installer is not updating my terminal python version.</p>
15
2009-11-06T12:45:57Z
1,687,431
<p>I believe Python 3 can coexist with Python 2. Try invoking it using "python3" or "python3.1". If it fails, you might need to uninstall 2.6 before installing 3.1. </p>
0
2009-11-06T12:57:00Z
[ "python", "osx", "python-3.x" ]
Updating Python on Mac
1,687,357
<p>I wanted to update my python 2.6.1 to 3.x on mac but i was wondering if its possible to do it using terminal or i have to download the installer from python website? </p> <p>The reason why i am asking this question is because installer is not updating my terminal python version.</p>
15
2009-11-06T12:45:57Z
1,687,456
<p>The default Python on OS X shouldn't be messed with as it's used by the OS itself. If your default is 2.6.1 then you must have Snow Leopard.</p> <p>If you just install from the <a href="http://www.python.org/ftp/python/3.1.1/python-3.1.1.dmg">standard 3.1 disk image</a> then you can invoke it using <code>python3.1<...
23
2009-11-06T13:00:27Z
[ "python", "osx", "python-3.x" ]
Updating Python on Mac
1,687,357
<p>I wanted to update my python 2.6.1 to 3.x on mac but i was wondering if its possible to do it using terminal or i have to download the installer from python website? </p> <p>The reason why i am asking this question is because installer is not updating my terminal python version.</p>
15
2009-11-06T12:45:57Z
1,688,349
<p>I personally wouldn't mess around with OSX's python like they said. My personally preference for stuff like this is just using MacPorts and installing the versions I want via command line. MacPorts puts everything into a separate direction (under /opt I believe), so it doesn't override or directly interfere with the...
2
2009-11-06T15:34:51Z
[ "python", "osx", "python-3.x" ]
Updating Python on Mac
1,687,357
<p>I wanted to update my python 2.6.1 to 3.x on mac but i was wondering if its possible to do it using terminal or i have to download the installer from python website? </p> <p>The reason why i am asking this question is because installer is not updating my terminal python version.</p>
15
2009-11-06T12:45:57Z
10,867,394
<p>I wanted to achieve the same today. The Mac with Snow Leopard comes with Python 2.6.1 version.</p> <p>Since multiple Python versions can coexist, I downloaded Python 3.2.3 from: <a href="http://www.python.org/getit/" rel="nofollow">http://www.python.org/getit/</a></p> <p>After installation the newer Python will b...
0
2012-06-03T02:08:51Z
[ "python", "osx", "python-3.x" ]
Updating Python on Mac
1,687,357
<p>I wanted to update my python 2.6.1 to 3.x on mac but i was wondering if its possible to do it using terminal or i have to download the installer from python website? </p> <p>The reason why i am asking this question is because installer is not updating my terminal python version.</p>
15
2009-11-06T12:45:57Z
25,224,377
<p>Echoing above on not messing with OS X install. Have been faced with a couple of reinstalls thinking I could beat the system. The <a href="http://www.python.org/ftp/python/3.1.1/python-3.1.1.dmg" rel="nofollow">3.1 install</a> Scott Griffiths offers above works fine with Yosemite, for any Beta testers out there.. ...
0
2014-08-10T00:20:08Z
[ "python", "osx", "python-3.x" ]
Updating Python on Mac
1,687,357
<p>I wanted to update my python 2.6.1 to 3.x on mac but i was wondering if its possible to do it using terminal or i have to download the installer from python website? </p> <p>The reason why i am asking this question is because installer is not updating my terminal python version.</p>
15
2009-11-06T12:45:57Z
25,960,643
<p>Python 2.7 and 3 can co-exist.<br> Python version shows on terminal is 2.7, but you can invoke it using "python3", see this:</p> <pre><code>PeiwenMAC:git Peiwen$ python --version Python 2.7.2 PeiwenMAC:git Peiwen$ python3 Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21) [GCC 4.2.1 (Apple Inc. build 5666) ...
0
2014-09-21T15:16:05Z
[ "python", "osx", "python-3.x" ]
Updating Python on Mac
1,687,357
<p>I wanted to update my python 2.6.1 to 3.x on mac but i was wondering if its possible to do it using terminal or i have to download the installer from python website? </p> <p>The reason why i am asking this question is because installer is not updating my terminal python version.</p>
15
2009-11-06T12:45:57Z
36,889,070
<p>using Homebrew just do:</p> <pre><code>brew install python3 &amp;&amp; cp /usr/local/bin/python3 /usr/local/bin/python </code></pre> <p>done :)</p>
0
2016-04-27T11:56:01Z
[ "python", "osx", "python-3.x" ]
What is the default chunker for NLTK toolkit in Python?
1,687,510
<p>I am using their default POS tagging and default tokenization..and it seems sufficient. I'd like their default chunker too.</p> <p>I am reading the NLTK toolkit book, but it does not seem like they have a default chunker?</p>
9
2009-11-06T13:10:20Z
1,687,712
<p>You can get out of the box named entity chunking with the nltk.ne_chunk() method. It takes a list of POS tagged tuples:</p> <p><code>nltk.ne_chunk([('Barack', 'NNP'), ('Obama', 'NNP'), ('lives', 'NNS'), ('in', 'IN'), ('Washington', 'NNP')])</code></p> <p>results in:</p> <p><code>Tree('S', [Tree('PERSON', [('Bara...
9
2009-11-06T13:49:23Z
[ "python", "nlp", "nltk", "chunking" ]
What is the default chunker for NLTK toolkit in Python?
1,687,510
<p>I am using their default POS tagging and default tokenization..and it seems sufficient. I'd like their default chunker too.</p> <p>I am reading the NLTK toolkit book, but it does not seem like they have a default chunker?</p>
9
2009-11-06T13:10:20Z
1,691,962
<p>I couldn't find a default chunker/shallow parser either. Although the book describes how to build and train one with example features. Coming up with additional features to get good performance shouldn't be too difficult.</p> <p>See Chapter 7's section on <a href="http://nltk.googlecode.com/svn/trunk/doc/book/ch0...
8
2009-11-07T04:10:04Z
[ "python", "nlp", "nltk", "chunking" ]
sorl.thumbnail : 'thumbnail' is not a valid tag library?
1,687,530
<p>I am trying to install sorl.thumbnail but am getting the following error message:</p> <p>'thumbnail' is not a valid tag library: Could not load template library from django.templatetags.thumbnail, No module named PIL</p> <p>This error popped up in this question as well<br> <a href="http://stackoverflow.com/questio...
0
2009-11-06T13:15:21Z
1,687,606
<p>(Editing this, since I didn't read carefully enough)</p> <p><code>django.templatetags.thumbnail</code> is not, I think, where your thumbnail templatetags should be loading from ... I would think, if you put it in your project folder, it would be <code>myproject.sorl.thumbnail.templatetags.thumbnail</code>. </p> <...
0
2009-11-06T13:31:52Z
[ "python", "django", "google-app-engine", "sorl-thumbnail" ]
sorl.thumbnail : 'thumbnail' is not a valid tag library?
1,687,530
<p>I am trying to install sorl.thumbnail but am getting the following error message:</p> <p>'thumbnail' is not a valid tag library: Could not load template library from django.templatetags.thumbnail, No module named PIL</p> <p>This error popped up in this question as well<br> <a href="http://stackoverflow.com/questio...
0
2009-11-06T13:15:21Z
1,777,239
<p>Is is a typo in your question? You have mis-spelled 'thumbnails' - for the installed apps you have two l's, i.e.</p> <p><code>'sorl.thumbnaills'</code></p> <p>rather than </p> <pre><code>'sorl.thumbnails' </code></pre> <p>if you run <code>sync.db</code> does it return an error?</p>
1
2009-11-22T00:03:16Z
[ "python", "django", "google-app-engine", "sorl-thumbnail" ]
sorl.thumbnail : 'thumbnail' is not a valid tag library?
1,687,530
<p>I am trying to install sorl.thumbnail but am getting the following error message:</p> <p>'thumbnail' is not a valid tag library: Could not load template library from django.templatetags.thumbnail, No module named PIL</p> <p>This error popped up in this question as well<br> <a href="http://stackoverflow.com/questio...
0
2009-11-06T13:15:21Z
1,796,540
<p>It seems i only made the typo here on stackoverflow, in settings i have:</p> <pre><code>INSTALLED_APPS = ( 'jquery', 'blueprintcss', 'django.contrib.auth', 'django.contrib.sessions', 'django.contrib.admin', 'django.contrib.webdesign', 'django.contrib.flatpages', 'django.contrib.redirects', 'django.contrib.sites', '...
0
2009-11-25T12:14:17Z
[ "python", "django", "google-app-engine", "sorl-thumbnail" ]
How can I tell if a given method is a classmethod or instancemethod in Python?
1,687,531
<p>Checking to see if m.im_self is the class works some of the time but doesn't seem to be 100% reliable (ex. if you use multiple decorators on a method.)</p>
1
2009-11-06T13:15:48Z
1,687,727
<p>If it's a bound method <em>on the class</em> then it's a classmethod. </p> <pre><code>from inspect import ismethod, isclass def isclassmethod( m ): return ismethod(m) and isclass(m.__self__) </code></pre>
2
2009-11-06T13:52:42Z
[ "python", "class" ]
Why does an assignment for double-sliced numpy arrays not work?
1,687,566
<p>why do the following lines not work as I expect?</p> <pre><code>import numpy as np a = np.array([0,1,2,1,1]) a[a==1][1:] = 3 print a &gt;&gt;&gt; [0 1 2 1 1] # I would expect [0 1 2 3 3] </code></pre> <p>Is this a 'bug' or is there another recommended way to this?</p> <p>On the other hand, the following works:</p...
8
2009-11-06T13:21:56Z
1,687,628
<p>Because the a[a==1] part isn't actually a slice. It creates a new array. It makes sense when you think about it-- you're only taking the elements that satisfy the boolean condition (like a filter operation).</p>
4
2009-11-06T13:36:06Z
[ "python", "numpy", "variable-assignment", "slice" ]
Why does an assignment for double-sliced numpy arrays not work?
1,687,566
<p>why do the following lines not work as I expect?</p> <pre><code>import numpy as np a = np.array([0,1,2,1,1]) a[a==1][1:] = 3 print a &gt;&gt;&gt; [0 1 2 1 1] # I would expect [0 1 2 3 3] </code></pre> <p>Is this a 'bug' or is there another recommended way to this?</p> <p>On the other hand, the following works:</p...
8
2009-11-06T13:21:56Z
1,687,729
<p>It appears you simply can't do an assignment through a double-slice like that.</p> <p>This works though:</p> <pre><code>a[numpy.where(a==1)[0][1:]] = 3 </code></pre>
5
2009-11-06T13:53:36Z
[ "python", "numpy", "variable-assignment", "slice" ]
Why does an assignment for double-sliced numpy arrays not work?
1,687,566
<p>why do the following lines not work as I expect?</p> <pre><code>import numpy as np a = np.array([0,1,2,1,1]) a[a==1][1:] = 3 print a &gt;&gt;&gt; [0 1 2 1 1] # I would expect [0 1 2 3 3] </code></pre> <p>Is this a 'bug' or is there another recommended way to this?</p> <p>On the other hand, the following works:</p...
8
2009-11-06T13:21:56Z
1,687,772
<p>This does what you want</p> <pre><code>a[2:][a[2:]==1]=3 </code></pre>
0
2009-11-06T13:59:42Z
[ "python", "numpy", "variable-assignment", "slice" ]
Why does an assignment for double-sliced numpy arrays not work?
1,687,566
<p>why do the following lines not work as I expect?</p> <pre><code>import numpy as np a = np.array([0,1,2,1,1]) a[a==1][1:] = 3 print a &gt;&gt;&gt; [0 1 2 1 1] # I would expect [0 1 2 3 3] </code></pre> <p>Is this a 'bug' or is there another recommended way to this?</p> <p>On the other hand, the following works:</p...
8
2009-11-06T13:21:56Z
1,687,787
<p>It's related to how fancy indexing works. There is a thorough explanation <a href="http://mail.scipy.org/pipermail/numpy-discussion/2008-January/031101.html">here</a>. It is done this way to allow inplace modification with fancy indexing (ie <code>a[x&gt;3] *= 2</code>). A consequence of this is that you can't assig...
9
2009-11-06T14:01:06Z
[ "python", "numpy", "variable-assignment", "slice" ]
Python app distribution cross-platform
1,688,105
<p>I want to distribute my app on OSX (using py2app) and as a Debian package.</p> <p>The structure of my app is like:</p> <pre><code>app/ debian/ &lt;lots of debian related stuff&gt; scripts/ app app/ __init__.py app.py mod1/ __init__.py...
2
2009-11-06T14:55:06Z
1,688,350
<p>I'm not sure if this is the 'best practice' or not (I've not put much python software into proper distribution), but I would just make sure that the top-level app package was in <code>sys.path</code>. Something like putting the following into the top-level <code>__init__.py</code>:</p> <pre><code>try: import m...
5
2009-11-06T15:34:59Z
[ "python", "cross-platform", "setuptools", "py2app" ]
python cProfile and profile models skip functions
1,688,412
<p>basically the cProfile module skips some functions when i run it, and the normal profile module produces this error.</p> <pre><code> The debugged program raised the exception unhandled AssertionError "('Bad call', ('objects/controller/StageController.py', 9, '__init__'), &lt;frame object at 0x9bbc104&gt;, &lt;fr...
3
2009-11-06T15:45:31Z
1,689,671
<p><a href="http://bugs.python.org/issue1117670" rel="nofollow">Python Bug #1117670</a> seems to describe the same issue. A minimal test script to reproduce that similar problem also attached there. The bug has been marked as fixed.</p> <p><strong>See msg24185</strong> in the above Python Bug report <strong>for a work...
0
2009-11-06T19:12:13Z
[ "python", "profiler" ]
python cProfile and profile models skip functions
1,688,412
<p>basically the cProfile module skips some functions when i run it, and the normal profile module produces this error.</p> <pre><code> The debugged program raised the exception unhandled AssertionError "('Bad call', ('objects/controller/StageController.py', 9, '__init__'), &lt;frame object at 0x9bbc104&gt;, &lt;fr...
3
2009-11-06T15:45:31Z
1,691,796
<p>I've found the problem. <a href="http://psyco.sourceforge.net/" rel="nofollow">Psyco</a> the 'ObjectControl' class which my 'StageControl' inherited has a simple:</p> <pre><code>import psyco psyco.full() </code></pre> <p>INSIDE the class, which caused the error hence only the methods in the classes which inherited...
2
2009-11-07T02:44:22Z
[ "python", "profiler" ]
How flatten a list of lists one step
1,688,712
<p>I have a list of lists of tuples </p> <pre><code>A= [ [(1,2,3),(4,5,6)], [(7,8,9),(8,7,6),(5,4,3)],[(2,1,0),(1,3,5)] ] </code></pre> <p>The outer list can have any number of inner lists, the inner lists can have any number of tuples, a tuple always has 3 integers.</p> <p>I want to generate all combination of tupl...
2
2009-11-06T16:31:10Z
1,688,768
<pre><code>itertools.product(*A) </code></pre> <p>For more details check the <a href="http://www.python.org/doc/current/tutorial/controlflow.html#arbitrary-argument-lists">python tutorial</a></p>
10
2009-11-06T16:38:01Z
[ "python" ]
How flatten a list of lists one step
1,688,712
<p>I have a list of lists of tuples </p> <pre><code>A= [ [(1,2,3),(4,5,6)], [(7,8,9),(8,7,6),(5,4,3)],[(2,1,0),(1,3,5)] ] </code></pre> <p>The outer list can have any number of inner lists, the inner lists can have any number of tuples, a tuple always has 3 integers.</p> <p>I want to generate all combination of tupl...
2
2009-11-06T16:31:10Z
1,688,773
<p>This works for your example, if there is only one level of nested lists (no lists of lists of lists):</p> <pre><code>itertools.product(*A) </code></pre>
2
2009-11-06T16:38:27Z
[ "python" ]
How flatten a list of lists one step
1,688,712
<p>I have a list of lists of tuples </p> <pre><code>A= [ [(1,2,3),(4,5,6)], [(7,8,9),(8,7,6),(5,4,3)],[(2,1,0),(1,3,5)] ] </code></pre> <p>The outer list can have any number of inner lists, the inner lists can have any number of tuples, a tuple always has 3 integers.</p> <p>I want to generate all combination of tupl...
2
2009-11-06T16:31:10Z
1,688,775
<p>you can probably call itertools.product like so:</p> <pre><code>itertools.product(*A) # where A is your list of lists of tuples </code></pre> <p>This way it expands your list's elements into arguments for the function you are calling.</p>
2
2009-11-06T16:38:36Z
[ "python" ]
How flatten a list of lists one step
1,688,712
<p>I have a list of lists of tuples </p> <pre><code>A= [ [(1,2,3),(4,5,6)], [(7,8,9),(8,7,6),(5,4,3)],[(2,1,0),(1,3,5)] ] </code></pre> <p>The outer list can have any number of inner lists, the inner lists can have any number of tuples, a tuple always has 3 integers.</p> <p>I want to generate all combination of tupl...
2
2009-11-06T16:31:10Z
1,689,135
<p>This is not exactly one step, but this would do what you want if for some reason you don't want to use the itertools solution:</p> <pre><code>def crossprod(listoflists): if len(listoflists) == 1: return listoflists else: result = [] remaining_product = prod(listoflists[1:]) f...
1
2009-11-06T17:36:20Z
[ "python" ]
How flatten a list of lists one step
1,688,712
<p>I have a list of lists of tuples </p> <pre><code>A= [ [(1,2,3),(4,5,6)], [(7,8,9),(8,7,6),(5,4,3)],[(2,1,0),(1,3,5)] ] </code></pre> <p>The outer list can have any number of inner lists, the inner lists can have any number of tuples, a tuple always has 3 integers.</p> <p>I want to generate all combination of tupl...
2
2009-11-06T16:31:10Z
1,697,816
<pre><code>def flatten(A) answer = [] for i in A: if type(i) == list: ans.extend(i) else: ans.append(i) return ans </code></pre>
1
2009-11-08T20:23:23Z
[ "python" ]
How flatten a list of lists one step
1,688,712
<p>I have a list of lists of tuples </p> <pre><code>A= [ [(1,2,3),(4,5,6)], [(7,8,9),(8,7,6),(5,4,3)],[(2,1,0),(1,3,5)] ] </code></pre> <p>The outer list can have any number of inner lists, the inner lists can have any number of tuples, a tuple always has 3 integers.</p> <p>I want to generate all combination of tupl...
2
2009-11-06T16:31:10Z
4,495,999
<p>Late to the party but ...</p> <p>I'm new to python and come from a lisp background. This is what I came up with (check out the var names for lulz):</p> <pre><code>def flatten(lst): if lst: car,*cdr=lst if isinstance(car,(list)): if cdr: return flatten(car) + flatten(cdr) ...
2
2010-12-21T03:23:55Z
[ "python" ]
How flatten a list of lists one step
1,688,712
<p>I have a list of lists of tuples </p> <pre><code>A= [ [(1,2,3),(4,5,6)], [(7,8,9),(8,7,6),(5,4,3)],[(2,1,0),(1,3,5)] ] </code></pre> <p>The outer list can have any number of inner lists, the inner lists can have any number of tuples, a tuple always has 3 integers.</p> <p>I want to generate all combination of tupl...
2
2009-11-06T16:31:10Z
12,984,049
<p>This may also be achieved using list comprehension.</p> <pre><code>In [62]: A = [ [(1,2,3),(4,5,6)], [(7,8,9),(8,7,6),(5,4,3)],[(2,1,0),(1,3,5)] ] In [63]: improved_list = [num for elem in A for num in elem] In [64]: improved_list Out[64]: [(1, 2, 3), (4, 5, 6), (7, 8, 9), (8, 7, 6), (5, 4, 3), (2, 1, 0), (1, 3, ...
-1
2012-10-20T00:10:48Z
[ "python" ]
Datetime - 10 Hours
1,688,719
<p>Consider:</p> <pre><code>now = datetime.datetime.now() now datetime.datetime(2009, 11, 6, 16, 6, 42, 812098) </code></pre> <p>How would I create a new datetime object (<code>past</code>) and minus <code>n</code> values from the hours?</p>
3
2009-11-06T16:32:00Z
1,688,738
<p>Use <code>timedelta</code> in the <code>datetime</code> module:</p> <pre><code>import datetime now = datetime.datetime.now() past = now - datetime.timedelta(hours=10) </code></pre>
14
2009-11-06T16:34:05Z
[ "python", "datetime" ]
Datetime - 10 Hours
1,688,719
<p>Consider:</p> <pre><code>now = datetime.datetime.now() now datetime.datetime(2009, 11, 6, 16, 6, 42, 812098) </code></pre> <p>How would I create a new datetime object (<code>past</code>) and minus <code>n</code> values from the hours?</p>
3
2009-11-06T16:32:00Z
1,688,779
<p>Use a <a href="http://docs.python.org/library/datetime.html?highlight=timedelta#datetime.timedelta" rel="nofollow">timedelta</a> object.</p> <pre><code>&gt;&gt;&gt; now = datetime.datetime.now() &gt;&gt;&gt; now datetime.datetime(2009, 11, 6, 16, 35, 50, 593000) &gt;&gt;&gt; ten_hours = datetime.timedelta(hours=10)...
8
2009-11-06T16:39:10Z
[ "python", "datetime" ]
Datetime - 10 Hours
1,688,719
<p>Consider:</p> <pre><code>now = datetime.datetime.now() now datetime.datetime(2009, 11, 6, 16, 6, 42, 812098) </code></pre> <p>How would I create a new datetime object (<code>past</code>) and minus <code>n</code> values from the hours?</p>
3
2009-11-06T16:32:00Z
9,437,576
<p>Use a <a href="http://docs.python.org/library/datetime.html?highlight=timedelta#datetime.timedelta" rel="nofollow">timedelta</a> object.</p> <pre><code>from datetime import datetime back = datetime.now() - timedelta(hours=10) </code></pre>
0
2012-02-24T20:28:16Z
[ "python", "datetime" ]
Why am I getting a little-endian error when importing .so file in python
1,688,845
<p>Im attempting to use a C++ extension for Python called PySndObj. and getting an error I have never seen and cannot find anything about on the web :(</p> <p>ImportError: /home/nhnifong/SndObj-2.6.6/python/_sndobj.so: ELF file data encoding not little-endian</p> <p>I know that probably means the byte order is backwa...
1
2009-11-06T16:46:49Z
1,688,883
<p>You have to build the extension from source yourself.</p> <p>It was valiant of you to try and "reverse the bytes", but only certain sections of the ELF file have word-oriented (as opposed to byte-oriented) data.</p> <p>Furthermore, it's unlikely that the dll in question was compiled for your system's CPU architect...
4
2009-11-06T16:52:58Z
[ "python", "import" ]
Deleting from dict if found in new list in Python
1,688,863
<p>Say I have a dictionary with whatever number of values. And then I create a list. If any of the values of the list are found in the dictionary, regardless of whether or not it is a key or an index how do I delete the full value?</p> <p>E.g:</p> <pre><code>dictionary = {1:3,4:5} list = [1] ... dictionary = {4:5...
1
2009-11-06T16:49:34Z
1,688,894
<p>it's a bit complicated because of your "values" requirement:</p> <pre><code>&gt;&gt;&gt; dic = {1: 3, 4: 5} &gt;&gt;&gt; ls = set([1]) &gt;&gt;&gt; dels = [] &gt;&gt;&gt; for k, v in dic.items(): if k in ls or v in ls: dels.append(k) &gt;&gt;&gt; for i in dels: del dic[i] &gt;&gt;&gt; dic {4: 5} </co...
3
2009-11-06T16:54:50Z
[ "python", "dictionary", "merge", "list" ]
Deleting from dict if found in new list in Python
1,688,863
<p>Say I have a dictionary with whatever number of values. And then I create a list. If any of the values of the list are found in the dictionary, regardless of whether or not it is a key or an index how do I delete the full value?</p> <p>E.g:</p> <pre><code>dictionary = {1:3,4:5} list = [1] ... dictionary = {4:5...
1
2009-11-06T16:49:34Z
1,688,899
<pre><code>dictionary = {1:3,4:5} list = [1] for key in list: if key in dictionary: del dictionary[key] </code></pre>
1
2009-11-06T16:55:36Z
[ "python", "dictionary", "merge", "list" ]
Deleting from dict if found in new list in Python
1,688,863
<p>Say I have a dictionary with whatever number of values. And then I create a list. If any of the values of the list are found in the dictionary, regardless of whether or not it is a key or an index how do I delete the full value?</p> <p>E.g:</p> <pre><code>dictionary = {1:3,4:5} list = [1] ... dictionary = {4:5...
1
2009-11-06T16:49:34Z
1,688,900
<p>I would do something like:</p> <pre><code>for i in list: if dictionary.has_key(i): del dictionary[i] </code></pre> <p>But I am sure there are better ways.</p>
0
2009-11-06T16:55:41Z
[ "python", "dictionary", "merge", "list" ]
Deleting from dict if found in new list in Python
1,688,863
<p>Say I have a dictionary with whatever number of values. And then I create a list. If any of the values of the list are found in the dictionary, regardless of whether or not it is a key or an index how do I delete the full value?</p> <p>E.g:</p> <pre><code>dictionary = {1:3,4:5} list = [1] ... dictionary = {4:5...
1
2009-11-06T16:49:34Z
1,688,905
<pre><code>&gt;&gt;&gt; dictionary = {1:3,4:5} &gt;&gt;&gt; list = [1] &gt;&gt;&gt; for x in list: ... if x in dictionary: ... del(dictionary[x]) ... &gt;&gt;&gt; dictionary {4: 5} </code></pre>
1
2009-11-06T16:56:37Z
[ "python", "dictionary", "merge", "list" ]
Deleting from dict if found in new list in Python
1,688,863
<p>Say I have a dictionary with whatever number of values. And then I create a list. If any of the values of the list are found in the dictionary, regardless of whether or not it is a key or an index how do I delete the full value?</p> <p>E.g:</p> <pre><code>dictionary = {1:3,4:5} list = [1] ... dictionary = {4:5...
1
2009-11-06T16:49:34Z
1,688,911
<pre><code>for key, value in list(dic.items()): if key in lst or value in lst: del dic[key] </code></pre> <p>No need to create a separate list or dictionary. </p> <p>I interpreted "whether or not it is a key or an index" to mean "whether or not it is a key or a value [in the dictionary]"</p>
5
2009-11-06T16:57:28Z
[ "python", "dictionary", "merge", "list" ]
Deleting from dict if found in new list in Python
1,688,863
<p>Say I have a dictionary with whatever number of values. And then I create a list. If any of the values of the list are found in the dictionary, regardless of whether or not it is a key or an index how do I delete the full value?</p> <p>E.g:</p> <pre><code>dictionary = {1:3,4:5} list = [1] ... dictionary = {4:5...
1
2009-11-06T16:49:34Z
1,689,016
<p>A few more testcases to define how I interpret your question:</p> <pre><code>#!/usr/bin/env python def test(beforedic,afterdic,removelist): d = beforedic l = removelist for i in l: for (k,v) in list(d.items()): if k == i or v == i: del d[k] assert d == afterdic,...
0
2009-11-06T17:16:30Z
[ "python", "dictionary", "merge", "list" ]
Deleting from dict if found in new list in Python
1,688,863
<p>Say I have a dictionary with whatever number of values. And then I create a list. If any of the values of the list are found in the dictionary, regardless of whether or not it is a key or an index how do I delete the full value?</p> <p>E.g:</p> <pre><code>dictionary = {1:3,4:5} list = [1] ... dictionary = {4:5...
1
2009-11-06T16:49:34Z
1,689,183
<p>If the dictionary is small enough, it's easier to just make a new one. Removing all items whose key is in the set <code>s</code> from the dictionary <code>d</code>:</p> <pre><code>d = dict((k, v) for (k, v) in d.items() if not k in s) </code></pre> <p>Removing all items whose key or value is in the set <code>s</c...
0
2009-11-06T17:44:17Z
[ "python", "dictionary", "merge", "list" ]
Deleting from dict if found in new list in Python
1,688,863
<p>Say I have a dictionary with whatever number of values. And then I create a list. If any of the values of the list are found in the dictionary, regardless of whether or not it is a key or an index how do I delete the full value?</p> <p>E.g:</p> <pre><code>dictionary = {1:3,4:5} list = [1] ... dictionary = {4:5...
1
2009-11-06T16:49:34Z
1,697,826
<pre><code>def remKeys(dictionary, list): for i in list: if i in dictionary.keys(): dictionary.pop(i) return dictionary </code></pre>
0
2009-11-08T20:27:37Z
[ "python", "dictionary", "merge", "list" ]