title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
Shorter, more pythonic way of writing an if statement
1,319,214
<p>I have this</p> <pre><code>bc = 'off' if c.page == 'blog': bc = 'on' print bc </code></pre> <p>Is there a more pythonic (and/or shorter) way of writing this in python?</p>
38
2009-08-23T18:33:08Z
1,319,219
<p>Shortest one should be:</p> <pre><code>bc = 'on' if c.page=='blog' else 'off' </code></pre> <p>Generally this might look a bit confusing, so you should only use it when it is clear what it means. Don't use it for big boolean clauses, since it begins to look ugly fast.</p>
80
2009-08-23T18:34:47Z
[ "python", "if-statement" ]
Shorter, more pythonic way of writing an if statement
1,319,214
<p>I have this</p> <pre><code>bc = 'off' if c.page == 'blog': bc = 'on' print bc </code></pre> <p>Is there a more pythonic (and/or shorter) way of writing this in python?</p>
38
2009-08-23T18:33:08Z
1,319,223
<p>Or you could use an inline if statement:</p> <pre><code>&gt;&gt;&gt; cpage = 'blog' &gt;&gt;&gt; bc = 'on' if cpage == 'blog' else 'off' &gt;&gt;&gt; bc 'on' &gt;&gt;&gt; cpage = 'asdf' &gt;&gt;&gt; bc = 'on' if cpage == 'blog' else 'off' &gt;&gt;&gt; bc 'off' </code></pre> <p>There's a bit of a writeup on that fe...
13
2009-08-23T18:35:56Z
[ "python", "if-statement" ]
Shorter, more pythonic way of writing an if statement
1,319,214
<p>I have this</p> <pre><code>bc = 'off' if c.page == 'blog': bc = 'on' print bc </code></pre> <p>Is there a more pythonic (and/or shorter) way of writing this in python?</p>
38
2009-08-23T18:33:08Z
1,319,289
<p>Well, not being a python guy please take this with a huge grain of salt, but having written (and, with more difficulty, <em>read</em>) a lot of clever code over the years, I find myself with a strong preference now for readable code. I got the gist of what your original code was doing even though I'm a nobody as a ...
25
2009-08-23T19:03:25Z
[ "python", "if-statement" ]
Shorter, more pythonic way of writing an if statement
1,319,214
<p>I have this</p> <pre><code>bc = 'off' if c.page == 'blog': bc = 'on' print bc </code></pre> <p>Is there a more pythonic (and/or shorter) way of writing this in python?</p>
38
2009-08-23T18:33:08Z
1,319,479
<p>This is:</p> <ol> <li>definitely shorter</li> <li>arguably Pythonic (pre-Python 2.5, which introduced the controversial <code>X if Z else Y</code> syntax)</li> <li><p>questionably readable. With those caveats in mind, here it goes:</p> <pre><code>bc = ("off","on")[c.page=="blog"] </code></pre></li> </ol> <p>EDIT...
58
2009-08-23T20:33:02Z
[ "python", "if-statement" ]
Shorter, more pythonic way of writing an if statement
1,319,214
<p>I have this</p> <pre><code>bc = 'off' if c.page == 'blog': bc = 'on' print bc </code></pre> <p>Is there a more pythonic (and/or shorter) way of writing this in python?</p>
38
2009-08-23T18:33:08Z
1,319,687
<p>You can use,</p> <pre><code>a = b if c else d </code></pre> <p>but if you are using a python version prior to 2.5,</p> <pre><code>bc = c.page == "blog" and "on" or "off" </code></pre> <p>can do the trick also.</p>
2
2009-08-23T22:05:59Z
[ "python", "if-statement" ]
Shorter, more pythonic way of writing an if statement
1,319,214
<p>I have this</p> <pre><code>bc = 'off' if c.page == 'blog': bc = 'on' print bc </code></pre> <p>Is there a more pythonic (and/or shorter) way of writing this in python?</p>
38
2009-08-23T18:33:08Z
1,320,324
<p>Another possibility is to use a dict if you can compute the values outside of the function that accesses them (i.e. the values are static, which also addresses the evaluation issue in scrible's answer's comments).</p> <pre><code>want_bc = {True: "on", False: "off"} # ... bc = want_bc[c.page == "blog"] </code></pre>...
3
2009-08-24T03:10:48Z
[ "python", "if-statement" ]
What is the most efficient way to add an element to a list only if isn't there yet?
1,319,254
<p>I have the following code in Python:</p> <pre><code>def point_to_index(point): if point not in points: points.append(point) return points.index(point) </code></pre> <p>This code is awfully inefficient, especially since I expect <code>points</code> to grow to hold a few million elements.</p> <p>If ...
7
2009-08-23T18:50:41Z
1,319,270
<pre><code>def point_to_index(point): try: return points.index(point) except: points.append(point) return len(points)-1 </code></pre> <p><strong>Update:</strong> Added in Nathan's exception code.</p>
2
2009-08-23T18:54:33Z
[ "python", "list", "optimization" ]
What is the most efficient way to add an element to a list only if isn't there yet?
1,319,254
<p>I have the following code in Python:</p> <pre><code>def point_to_index(point): if point not in points: points.append(point) return points.index(point) </code></pre> <p>This code is awfully inefficient, especially since I expect <code>points</code> to grow to hold a few million elements.</p> <p>If ...
7
2009-08-23T18:50:41Z
1,319,272
<p>You want to use a <a href="http://docs.python.org/library/stdtypes.html#set">set</a>:</p> <pre><code>&gt;&gt;&gt; x = set() &gt;&gt;&gt; x set([]) &gt;&gt;&gt; x.add(1) &gt;&gt;&gt; x set([1]) &gt;&gt;&gt; x.add(1) &gt;&gt;&gt; x set([1]) </code></pre> <p>A set contains only one instance of any item you add, and i...
8
2009-08-23T18:55:27Z
[ "python", "list", "optimization" ]
What is the most efficient way to add an element to a list only if isn't there yet?
1,319,254
<p>I have the following code in Python:</p> <pre><code>def point_to_index(point): if point not in points: points.append(point) return points.index(point) </code></pre> <p>This code is awfully inefficient, especially since I expect <code>points</code> to grow to hold a few million elements.</p> <p>If ...
7
2009-08-23T18:50:41Z
1,319,287
<p>This will traverse at most once:</p> <pre><code>def point_to_index(point): try: return points.index(point) except ValueError: points.append(point) return len(points)-1 </code></pre> <p>You may also want to try this version, which takes into account that matches are likely to be nea...
10
2009-08-23T19:02:13Z
[ "python", "list", "optimization" ]
What is the most efficient way to add an element to a list only if isn't there yet?
1,319,254
<p>I have the following code in Python:</p> <pre><code>def point_to_index(point): if point not in points: points.append(point) return points.index(point) </code></pre> <p>This code is awfully inefficient, especially since I expect <code>points</code> to grow to hold a few million elements.</p> <p>If ...
7
2009-08-23T18:50:41Z
1,319,470
<p>As others said, consider using set or dict. You don't explain why you need the indices. If they are needed only to assign unique ids to the points (and I can't easily come up with another reason for using them), then dict will indeed work much better, e.g.,</p> <pre><code>points = {} def point_to_index(point): ...
1
2009-08-23T20:27:37Z
[ "python", "list", "optimization" ]
What is the most efficient way to add an element to a list only if isn't there yet?
1,319,254
<p>I have the following code in Python:</p> <pre><code>def point_to_index(point): if point not in points: points.append(point) return points.index(point) </code></pre> <p>This code is awfully inefficient, especially since I expect <code>points</code> to grow to hold a few million elements.</p> <p>If ...
7
2009-08-23T18:50:41Z
1,321,039
<p>If you're worried about memory usage, but want to optimize the common case, keep a dictionary with the last n points and their indexes. points_dict = dictionary, max_cache = size of the cache.</p> <pre><code>def point_to_index(point): try: return points_dict.get(point, points.index(point)) except: ...
5
2009-08-24T08:06:53Z
[ "python", "list", "optimization" ]
What is the most efficient way to add an element to a list only if isn't there yet?
1,319,254
<p>I have the following code in Python:</p> <pre><code>def point_to_index(point): if point not in points: points.append(point) return points.index(point) </code></pre> <p>This code is awfully inefficient, especially since I expect <code>points</code> to grow to hold a few million elements.</p> <p>If ...
7
2009-08-23T18:50:41Z
1,321,086
<p>What you really want is an ordered dict (key insertion determines the order):</p> <ul> <li>Recipe: <a href="http://code.activestate.com/recipes/107747/" rel="nofollow">http://code.activestate.com/recipes/107747/</a></li> <li>PEP: <a href="http://www.python.org/dev/peps/pep-0372/" rel="nofollow">http://www.python.or...
1
2009-08-24T08:20:32Z
[ "python", "list", "optimization" ]
Combining two lists and removing duplicates, without removing duplicates in original list
1,319,338
<p>I have two lists that i need to combine where the second list has any duplicates of the first list ignored. .. A bit hard to explain, so let me show an example of what the code looks like, and what i want as a result.</p> <pre><code>first_list = [1, 2, 2, 5] second_list = [2, 5, 7, 9] # The result of combining th...
31
2009-08-23T19:27:58Z
1,319,353
<p>You need to append to the first list those elements of the second list that aren't in the first - sets are the easiest way of determining which elements they are, like this:</p> <pre><code>first_list = [1, 2, 2, 5] second_list = [2, 5, 7, 9] in_first = set(first_list) in_second = set(second_list) in_second_but_no...
59
2009-08-23T19:32:09Z
[ "python", "list" ]
Combining two lists and removing duplicates, without removing duplicates in original list
1,319,338
<p>I have two lists that i need to combine where the second list has any duplicates of the first list ignored. .. A bit hard to explain, so let me show an example of what the code looks like, and what i want as a result.</p> <pre><code>first_list = [1, 2, 2, 5] second_list = [2, 5, 7, 9] # The result of combining th...
31
2009-08-23T19:27:58Z
1,319,354
<pre><code>resulting_list = first_list + [i for i in second_list if i not in first_list] </code></pre>
1
2009-08-23T19:32:18Z
[ "python", "list" ]
Combining two lists and removing duplicates, without removing duplicates in original list
1,319,338
<p>I have two lists that i need to combine where the second list has any duplicates of the first list ignored. .. A bit hard to explain, so let me show an example of what the code looks like, and what i want as a result.</p> <pre><code>first_list = [1, 2, 2, 5] second_list = [2, 5, 7, 9] # The result of combining th...
31
2009-08-23T19:27:58Z
1,319,355
<pre><code>resulting_list = list(first_list) resulting_list.extend(x for x in second_list if x not in resulting_list) </code></pre>
19
2009-08-23T19:32:42Z
[ "python", "list" ]
Combining two lists and removing duplicates, without removing duplicates in original list
1,319,338
<p>I have two lists that i need to combine where the second list has any duplicates of the first list ignored. .. A bit hard to explain, so let me show an example of what the code looks like, and what i want as a result.</p> <pre><code>first_list = [1, 2, 2, 5] second_list = [2, 5, 7, 9] # The result of combining th...
31
2009-08-23T19:27:58Z
12,389,407
<p>This might help </p> <pre><code>def union(a,b): for e in b: if e not in a: a.append(e) </code></pre> <p>The union function merges the second list into first, with out duplicating an element of a, if it's already in a. Similar to set union operator. This function does not change b. If a=[1...
0
2012-09-12T13:34:53Z
[ "python", "list" ]
Combining two lists and removing duplicates, without removing duplicates in original list
1,319,338
<p>I have two lists that i need to combine where the second list has any duplicates of the first list ignored. .. A bit hard to explain, so let me show an example of what the code looks like, and what i want as a result.</p> <pre><code>first_list = [1, 2, 2, 5] second_list = [2, 5, 7, 9] # The result of combining th...
31
2009-08-23T19:27:58Z
14,832,994
<p>You can use sets:</p> <pre><code>first_list = [1, 2, 2, 5] second_list = [2, 5, 7, 9] resultList= List(set(first_list)|set(second_list)) resultList=[1,2,5,7,9] </code></pre>
4
2013-02-12T12:51:00Z
[ "python", "list" ]
Combining two lists and removing duplicates, without removing duplicates in original list
1,319,338
<p>I have two lists that i need to combine where the second list has any duplicates of the first list ignored. .. A bit hard to explain, so let me show an example of what the code looks like, and what i want as a result.</p> <pre><code>first_list = [1, 2, 2, 5] second_list = [2, 5, 7, 9] # The result of combining th...
31
2009-08-23T19:27:58Z
29,943,019
<pre><code> first_list = [1, 2, 2, 5] second_list = [2, 5, 7, 9] newList=[] for i in first_list: newList.append(i) for z in second_list: if z not in newList: newList.append(z) newList.sort() print newList </code></pre> <p>[1, 2, 2, 5, 7, 9]</p>
0
2015-04-29T11:56:40Z
[ "python", "list" ]
Combining two lists and removing duplicates, without removing duplicates in original list
1,319,338
<p>I have two lists that i need to combine where the second list has any duplicates of the first list ignored. .. A bit hard to explain, so let me show an example of what the code looks like, and what i want as a result.</p> <pre><code>first_list = [1, 2, 2, 5] second_list = [2, 5, 7, 9] # The result of combining th...
31
2009-08-23T19:27:58Z
33,792,245
<p>You can also combine RichieHindle's and Ned Batchelder's responses for an <em><a href="http://stackoverflow.com/a/3906036/320036">average-case</a> O(m+n)</em> algorithm that preserves order:</p> <pre><code>first_list = [1, 2, 2, 5] second_list = [2, 5, 7, 9] fs = set(first_list) resulting_list = first_list + [x fo...
0
2015-11-18T23:07:03Z
[ "python", "list" ]
Need Help using XPath in ElementTree
1,319,385
<p>I am having a heck of a time using ElementTree 1.3 in Python. Essentially, ElementTree does absolutely nothing.</p> <p>My XML file looks like the following:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2008-08-19"&gt; &lt;Items&gt; ...
26
2009-08-23T19:48:21Z
1,319,417
<p>There are 2 problems that you have.</p> <p>1) <code>element</code> contains only the root element, not recursively the whole document. It is of type Element not ElementTree.</p> <p>2) Your search string needs to use namespaces if you keep the namespace in the XML.</p> <p><strong>To fix problem #1:</strong> </p> ...
47
2009-08-23T20:02:48Z
[ "python", "xml", "xpath", "elementtree" ]
Need Help using XPath in ElementTree
1,319,385
<p>I am having a heck of a time using ElementTree 1.3 in Python. Essentially, ElementTree does absolutely nothing.</p> <p>My XML file looks like the following:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2008-08-19"&gt; &lt;Items&gt; ...
26
2009-08-23T19:48:21Z
1,319,457
<p>Element tree uses namespaces so all the elements in your xml have name like {<a href="http://webservices.amazon.com/AWSECommerceService/2008-08-19">http://webservices.amazon.com/AWSECommerceService/2008-08-19</a>}Items</p> <p>So make the search include the namespace e.g.</p> <pre><code>search = '{http://webservice...
5
2009-08-23T20:23:54Z
[ "python", "xml", "xpath", "elementtree" ]
Need Help using XPath in ElementTree
1,319,385
<p>I am having a heck of a time using ElementTree 1.3 in Python. Essentially, ElementTree does absolutely nothing.</p> <p>My XML file looks like the following:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2008-08-19"&gt; &lt;Items&gt; ...
26
2009-08-23T19:48:21Z
1,319,575
<pre><code>from xml.etree import ElementTree as ET tree = ET.parse("output.xml") namespace = tree.getroot().tag[1:].split("}")[0] amount = tree.find(".//{%s}Amount" % namespace).text </code></pre> <p>Also, consider using <a href="http://codespeak.net/lxml/">lxml</a>. It's way faster.</p> <pre><code>from lxml import ...
6
2009-08-23T21:11:16Z
[ "python", "xml", "xpath", "elementtree" ]
Need Help using XPath in ElementTree
1,319,385
<p>I am having a heck of a time using ElementTree 1.3 in Python. Essentially, ElementTree does absolutely nothing.</p> <p>My XML file looks like the following:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2008-08-19"&gt; &lt;Items&gt; ...
26
2009-08-23T19:48:21Z
10,343,185
<p>I ended up stripping out the xmlns from the raw xml like that:</p> <pre><code>def strip_ns(xml_string): return re.sub('xmlns="[^"]+"', '', xml_string) </code></pre> <p>Obviously be very careful with this, but it worked well for me.</p>
5
2012-04-27T00:24:28Z
[ "python", "xml", "xpath", "elementtree" ]
Is this a good approach to avoid using SQLAlchemy/SQLObject?
1,319,585
<p>Rather than use an ORM, I am considering the following approach in Python and MySQL with no ORM (SQLObject/SQLAlchemy). I would like to get some feedback on whether this seems likely to have any negative long-term consequences since in the short-term view it seems fine from what I can tell.</p> <p>Rather than trans...
3
2009-08-23T21:15:05Z
1,319,598
<p>That doesn't do away with the need for an ORM. That <strong>is</strong> an ORM. In which case, why reinvent the wheel?</p> <p>Is there a compelling reason you're trying to avoid using an established ORM?</p>
8
2009-08-23T21:23:54Z
[ "python", "sqlalchemy", "sqlobject" ]
Is this a good approach to avoid using SQLAlchemy/SQLObject?
1,319,585
<p>Rather than use an ORM, I am considering the following approach in Python and MySQL with no ORM (SQLObject/SQLAlchemy). I would like to get some feedback on whether this seems likely to have any negative long-term consequences since in the short-term view it seems fine from what I can tell.</p> <p>Rather than trans...
3
2009-08-23T21:15:05Z
1,319,662
<p>You will still be using SQLAlchemy. ResultProxy is actually a dictionary once you go for .fetchmany() or similar.</p> <p>Use SQLAlchemy as a tool that makes managing connections easier, as well as executing statements. Documentation is pretty much separated in sections, so you will be reading just the part that you...
2
2009-08-23T21:48:45Z
[ "python", "sqlalchemy", "sqlobject" ]
Is this a good approach to avoid using SQLAlchemy/SQLObject?
1,319,585
<p>Rather than use an ORM, I am considering the following approach in Python and MySQL with no ORM (SQLObject/SQLAlchemy). I would like to get some feedback on whether this seems likely to have any negative long-term consequences since in the short-term view it seems fine from what I can tell.</p> <p>Rather than trans...
3
2009-08-23T21:15:05Z
1,319,674
<p>web.py has in a decent db abstraction too (not an ORM). Queries are written in SQL (not specific to any rdbms), but your code remains compatible with any of the supported dbs (sqlite, mysql, postresql, and others).</p> <p>from <a href="http://webpy.org/cookbook/select" rel="nofollow">http://webpy.org/cookbook/sele...
0
2009-08-23T21:55:10Z
[ "python", "sqlalchemy", "sqlobject" ]
Proper way to declare custom exceptions in modern Python?
1,319,615
<p>What's the proper way to declare custom exception classes in modern Python? My primary goal is to follow whatever standard other exception classes have, so that (for instance) any extra string I include in the exception is printed out by whatever tool caught the exception.</p> <p>By "modern Python" I mean something...
595
2009-08-23T21:29:29Z
1,319,660
<p>You should override <code>__repr__</code> or <code>__unicode__</code> methods instead of using message, the args you provide when you construct the exception will be in <code>args</code> member variable when you need.</p>
10
2009-08-23T21:46:54Z
[ "python", "exception" ]
Proper way to declare custom exceptions in modern Python?
1,319,615
<p>What's the proper way to declare custom exception classes in modern Python? My primary goal is to follow whatever standard other exception classes have, so that (for instance) any extra string I include in the exception is printed out by whatever tool caught the exception.</p> <p>By "modern Python" I mean something...
595
2009-08-23T21:29:29Z
1,319,675
<p>Maybe I missed the question, but why not:</p> <pre><code>class MyException(Exception): pass </code></pre> <p><strong>Edit:</strong> to override something (or pass extra args), do this:</p> <pre><code>class ValidationError(Exception): def __init__(self, message, errors): # Call the base class cons...
578
2009-08-23T21:55:23Z
[ "python", "exception" ]
Proper way to declare custom exceptions in modern Python?
1,319,615
<p>What's the proper way to declare custom exception classes in modern Python? My primary goal is to follow whatever standard other exception classes have, so that (for instance) any extra string I include in the exception is printed out by whatever tool caught the exception.</p> <p>By "modern Python" I mean something...
595
2009-08-23T21:29:29Z
1,319,680
<p>No, "message" is not forbidden. It's just deprecated. You application will work fine with using message. But you may want to get rid of the deprecation error, of course.</p> <p>When you create custom Exception classes for your application, many of them do not subclass just from Exception, but from others, like Valu...
4
2009-08-23T21:58:47Z
[ "python", "exception" ]
Proper way to declare custom exceptions in modern Python?
1,319,615
<p>What's the proper way to declare custom exception classes in modern Python? My primary goal is to follow whatever standard other exception classes have, so that (for instance) any extra string I include in the exception is printed out by whatever tool caught the exception.</p> <p>By "modern Python" I mean something...
595
2009-08-23T21:29:29Z
10,270,732
<p>With modern Python Exceptions, you don't need to abuse <code>.message</code>, or override <code>.__str__()</code> or <code>.__repr__()</code> or any of it. If all you want is an informative message when your exception is raised, do this:</p> <pre><code>class MyException(Exception): pass raise MyException("My h...
223
2012-04-22T18:18:17Z
[ "python", "exception" ]
Proper way to declare custom exceptions in modern Python?
1,319,615
<p>What's the proper way to declare custom exception classes in modern Python? My primary goal is to follow whatever standard other exception classes have, so that (for instance) any extra string I include in the exception is printed out by whatever tool caught the exception.</p> <p>By "modern Python" I mean something...
595
2009-08-23T21:29:29Z
18,108,623
<p>see how exceptions work by default if one <em>vs</em> more attributes are used (tracebacks omitted):</p> <pre><code>&gt;&gt;&gt; raise Exception('bad thing happened') Exception: bad thing happened &gt;&gt;&gt; raise Exception('bad thing happened', 'code is broken') Exception: ('bad thing happened', 'code is broken...
21
2013-08-07T16:23:56Z
[ "python", "exception" ]
Proper way to declare custom exceptions in modern Python?
1,319,615
<p>What's the proper way to declare custom exception classes in modern Python? My primary goal is to follow whatever standard other exception classes have, so that (for instance) any extra string I include in the exception is printed out by whatever tool caught the exception.</p> <p>By "modern Python" I mean something...
595
2009-08-23T21:29:29Z
26,938,914
<blockquote> <h1>"Proper way to declare custom exceptions in modern Python?"</h1> </blockquote> <p>This is fine, unless your exception is really a type of a more specific exception:</p> <pre><code>class MyException(Exception): pass </code></pre> <p>Or better (maybe perfect), instead of <code>pass</code> give a...
53
2014-11-14T21:09:22Z
[ "python", "exception" ]
Key-ordered dict in Python
1,319,763
<p>I am looking for a solid implementation of an ordered associative array, that is, an ordered dictionary. I want the ordering in terms of keys, not of insertion order.</p> <p>More precisely, I am looking for a space-efficent implementation of a int-to-float (or string-to-float for another use case) mapping structur...
24
2009-08-23T22:33:49Z
1,319,790
<p>An ordered tree is usually better for this cases, but random access is going to be log(n). You should keep into account also insertion and removal costs...</p>
4
2009-08-23T22:44:14Z
[ "python", "data-structures", "collections", "dictionary" ]
Key-ordered dict in Python
1,319,763
<p>I am looking for a solid implementation of an ordered associative array, that is, an ordered dictionary. I want the ordering in terms of keys, not of insertion order.</p> <p>More precisely, I am looking for a space-efficent implementation of a int-to-float (or string-to-float for another use case) mapping structur...
24
2009-08-23T22:33:49Z
1,319,892
<p>You could build a dict that allows traversal by storing a pair <code>(value, next_key)</code> in each position. </p> <p>Random access:</p> <pre><code>my_dict[k][0] # for a key k </code></pre> <p>Traversal:</p> <pre><code>k = start_key # stored somewhere while k is not None: # next_key is None at the end...
1
2009-08-23T23:42:24Z
[ "python", "data-structures", "collections", "dictionary" ]
Key-ordered dict in Python
1,319,763
<p>I am looking for a solid implementation of an ordered associative array, that is, an ordered dictionary. I want the ordering in terms of keys, not of insertion order.</p> <p>More precisely, I am looking for a space-efficent implementation of a int-to-float (or string-to-float for another use case) mapping structur...
24
2009-08-23T22:33:49Z
1,320,113
<p>I'm not sure which python version are you working in, but in case you like to experiment, Python 3.1 includes and official implementation of Ordered dictionaries: <a href="http://www.python.org/dev/peps/pep-0372/" rel="nofollow">http://www.python.org/dev/peps/pep-0372/</a> <a href="http://docs.python.org/3.1/whatsne...
1
2009-08-24T01:37:18Z
[ "python", "data-structures", "collections", "dictionary" ]
Key-ordered dict in Python
1,319,763
<p>I am looking for a solid implementation of an ordered associative array, that is, an ordered dictionary. I want the ordering in terms of keys, not of insertion order.</p> <p>More precisely, I am looking for a space-efficent implementation of a int-to-float (or string-to-float for another use case) mapping structur...
24
2009-08-23T22:33:49Z
1,320,137
<p>here's a pastie: I Had a need for something similar. Note however that this specific implementation is immutable, there are no inserts, once the instance is created: The exact performance doesn't quite match what you're asking for, however. Lookup is O(log n) and full scan is O(n). This works using the <code>bis...
0
2009-08-24T01:49:00Z
[ "python", "data-structures", "collections", "dictionary" ]
Key-ordered dict in Python
1,319,763
<p>I am looking for a solid implementation of an ordered associative array, that is, an ordered dictionary. I want the ordering in terms of keys, not of insertion order.</p> <p>More precisely, I am looking for a space-efficent implementation of a int-to-float (or string-to-float for another use case) mapping structur...
24
2009-08-23T22:33:49Z
1,320,202
<p>"Random access O(1)" is an extremely exacting requirement which basically imposes an underlying hash table -- and I hope you do mean random READS only, because I think it can be mathematically proven than it's impossible in the general case to have O(1) writes as well as O(N) ordered iteration.</p> <p>I don't think...
27
2009-08-24T02:20:48Z
[ "python", "data-structures", "collections", "dictionary" ]
Key-ordered dict in Python
1,319,763
<p>I am looking for a solid implementation of an ordered associative array, that is, an ordered dictionary. I want the ordering in terms of keys, not of insertion order.</p> <p>More precisely, I am looking for a space-efficent implementation of a int-to-float (or string-to-float for another use case) mapping structur...
24
2009-08-23T22:33:49Z
1,320,943
<p>Here is my own implementation:</p> <pre><code>import bisect class KeyOrderedDict(object): __slots__ = ['d', 'l'] def __init__(self, *args, **kwargs): self.l = sorted(kwargs) self.d = kwargs def __setitem__(self, k, v): if not k in self.d: idx = bisect.bisect(self.l, k) ...
3
2009-08-24T07:38:59Z
[ "python", "data-structures", "collections", "dictionary" ]
Key-ordered dict in Python
1,319,763
<p>I am looking for a solid implementation of an ordered associative array, that is, an ordered dictionary. I want the ordering in terms of keys, not of insertion order.</p> <p>More precisely, I am looking for a space-efficent implementation of a int-to-float (or string-to-float for another use case) mapping structur...
24
2009-08-23T22:33:49Z
11,072,522
<p>The ordereddict package ( <a href="http://anthon.home.xs4all.nl/Python/ordereddict/" rel="nofollow">http://anthon.home.xs4all.nl/Python/ordereddict/</a> ) that I implemented back in 2007 includes sorteddict. sorteddict is a KSO ( Key Sorted Order) dictionary. It is implemented in C and very space efficient and seve...
1
2012-06-17T15:31:44Z
[ "python", "data-structures", "collections", "dictionary" ]
Key-ordered dict in Python
1,319,763
<p>I am looking for a solid implementation of an ordered associative array, that is, an ordered dictionary. I want the ordering in terms of keys, not of insertion order.</p> <p>More precisely, I am looking for a space-efficent implementation of a int-to-float (or string-to-float for another use case) mapping structur...
24
2009-08-23T22:33:49Z
18,091,573
<p>For "string to float" problem you can use a Trie - it provides O(1) access time and O(n) sorted iteration. By "sorted" I mean "sorted alphabetically by key" - it seems that the question implies the same.</p> <p>Some implementations (each with its own strong and weak points):</p> <ul> <li><a href="https://github.co...
0
2013-08-06T22:24:30Z
[ "python", "data-structures", "collections", "dictionary" ]
Key-ordered dict in Python
1,319,763
<p>I am looking for a solid implementation of an ordered associative array, that is, an ordered dictionary. I want the ordering in terms of keys, not of insertion order.</p> <p>More precisely, I am looking for a space-efficent implementation of a int-to-float (or string-to-float for another use case) mapping structur...
24
2009-08-23T22:33:49Z
22,996,715
<p>The <a href="http://www.grantjenks.com/docs/sortedcontainers/">sortedcontainers</a> module provides a <a href="http://www.grantjenks.com/docs/sortedcontainers/sorteddict.html">SortedDict</a> type that meets your requirements. It basically glues a <a href="http://www.grantjenks.com/docs/sortedcontainers/sortedlist.ht...
6
2014-04-10T18:58:34Z
[ "python", "data-structures", "collections", "dictionary" ]
How to submit data of a flash form? [python]
1,319,895
<p>I would like to know if it is possible to submit a flash form from python and, if it is, how? I have done form submitting from python before, but the forms were HTML not flash. I really have no idea on how to do this. In my research about this I kept getting 'Ming'. However, Ming is only to create .swf files and tha...
3
2009-08-23T23:42:52Z
1,319,907
<p>You can set the url attribute (I think it's url, please correct me if I'm wrong) on a Flash form control to a Python script - then it will pass it through HTTP POST like any normal HTML form.</p> <p>You've got nothing to be afraid of, it uses the same protocol to communicate, it's just a different submission proces...
1
2009-08-23T23:50:18Z
[ "python", "flash", "forms" ]
How to submit data of a flash form? [python]
1,319,895
<p>I would like to know if it is possible to submit a flash form from python and, if it is, how? I have done form submitting from python before, but the forms were HTML not flash. I really have no idea on how to do this. In my research about this I kept getting 'Ming'. However, Ming is only to create .swf files and tha...
3
2009-08-23T23:42:52Z
1,320,103
<p>For your flash app, there's no difference if the backend is python, php or anything, so you can follow a normal "php + flash contact form" guide and then build the backend using django or any other python web framework, receive the information from the http request (GET or POST, probably the last one) and do whateve...
0
2009-08-24T01:30:45Z
[ "python", "flash", "forms" ]
urlopen, BeautifulSoup and UTF-8 Issue
1,320,591
<p>I am just trying to retrieve a web page, but somehow a foreign character is embedded in the HTML file. This character is not visible when I use "View Source."</p> <pre><code>isbn = 9780141187983 url = "http://search.barnesandnoble.com/booksearch/isbninquiry.asp?ean=%s" % isbn opener = urllib2.build_opener() url_ope...
2
2009-08-24T05:17:24Z
1,320,669
<p>This error is probably actually happening when you try to <em>print</em> the representation of the BeautifulSoup file, which will happen automatically if, as I suspect, you are working in the interactive console. </p> <pre><code># This code will work fine, note we are assigning the result # of the BeautifulSoup o...
11
2009-08-24T05:58:34Z
[ "python", "utf-8", "urllib2", "beautifulsoup" ]
urlopen, BeautifulSoup and UTF-8 Issue
1,320,591
<p>I am just trying to retrieve a web page, but somehow a foreign character is embedded in the HTML file. This character is not visible when I use "View Source."</p> <pre><code>isbn = 9780141187983 url = "http://search.barnesandnoble.com/booksearch/isbninquiry.asp?ean=%s" % isbn opener = urllib2.build_opener() url_ope...
2
2009-08-24T05:17:24Z
34,416,469
<p>You could try the following :</p> <pre><code>import codecs f = codecs.open(filename,'r','utf-8') soup = BeautifulSoup(f.read(),"html.parser") </code></pre> <p>I encountered a similar problem with bs4</p>
0
2015-12-22T12:58:27Z
[ "python", "utf-8", "urllib2", "beautifulsoup" ]
How to encrypt a string using the key
1,320,671
<p>I have a 'public key' in a variable named varkey, for getting the public key I used the urllib and stored that public key in a variable. Now I want to encrypt a msg/string using the public key.</p> <p>It's ok if somebody could lead me to some library.</p>
2
2009-08-24T06:00:00Z
1,320,681
<p>You might want to have a look at:</p> <p><a href="http://www.example-code.com/python/encryption.asp" rel="nofollow">http://www.example-code.com/python/encryption.asp</a></p> <p>or this</p> <p><a href="http://passingcuriosity.com/2009/aes-encryption-in-python-with-m2crypto/" rel="nofollow">http://passingcuriosity....
0
2009-08-24T06:04:45Z
[ "python", "encryption" ]
How to encrypt a string using the key
1,320,671
<p>I have a 'public key' in a variable named varkey, for getting the public key I used the urllib and stored that public key in a variable. Now I want to encrypt a msg/string using the public key.</p> <p>It's ok if somebody could lead me to some library.</p>
2
2009-08-24T06:00:00Z
1,320,686
<p>You could use MD5 or SHA1 hashing along with your key...</p>
-2
2009-08-24T06:05:21Z
[ "python", "encryption" ]
How to encrypt a string using the key
1,320,671
<p>I have a 'public key' in a variable named varkey, for getting the public key I used the urllib and stored that public key in a variable. Now I want to encrypt a msg/string using the public key.</p> <p>It's ok if somebody could lead me to some library.</p>
2
2009-08-24T06:00:00Z
1,320,693
<p>From my recent python experience, python doesn't do encryption natively. You need to use an external (3rd party) package. Each of these, obviously, offers a different experience. Which are you using? This will probably determine how your syntax will vary.</p>
1
2009-08-24T06:06:10Z
[ "python", "encryption" ]
How to encrypt a string using the key
1,320,671
<p>I have a 'public key' in a variable named varkey, for getting the public key I used the urllib and stored that public key in a variable. Now I want to encrypt a msg/string using the public key.</p> <p>It's ok if somebody could lead me to some library.</p>
2
2009-08-24T06:00:00Z
1,480,380
<p>My blog post (the passingcuriosity.com link in John Boker's answer) does AES -- a symmetric encryption algorithm -- using the M2Crypto library. M2Crypto is a Python wrapper around OpenSSL. The API is pretty much a straight translation of OpenSSL's into Python, so the somewhat sketchy documentation shouldn't be too m...
6
2009-09-26T03:41:39Z
[ "python", "encryption" ]
How to encrypt a string using the key
1,320,671
<p>I have a 'public key' in a variable named varkey, for getting the public key I used the urllib and stored that public key in a variable. Now I want to encrypt a msg/string using the public key.</p> <p>It's ok if somebody could lead me to some library.</p>
2
2009-08-24T06:00:00Z
1,480,597
<p>Here's the script that demonstrates how to encrypt a message using M2Crypto (<code>$ easy_install m2crypto</code>) given that public key is in <code>varkey</code> variable:</p> <pre><code>#!/usr/bin/env python import urllib2 from M2Crypto import BIO, RSA def readkey(filename): try: key = open(filename)...
3
2009-09-26T06:46:29Z
[ "python", "encryption" ]
How to encrypt a string using the key
1,320,671
<p>I have a 'public key' in a variable named varkey, for getting the public key I used the urllib and stored that public key in a variable. Now I want to encrypt a msg/string using the public key.</p> <p>It's ok if somebody could lead me to some library.</p>
2
2009-08-24T06:00:00Z
3,123,241
<p>Very funny. Have you ever heard about "RSAError: data too large for key size" ? No???? Try your sample with more long message:</p> <pre><code>encrypted = rsa.public_encrypt('My blog post (the passingcuriosity.com link in John Boker's answer) does AES -- a symmetric encryption algorithm -- using the M2Crypto library...
1
2010-06-26T08:28:21Z
[ "python", "encryption" ]
Good graph traversal algorithm
1,320,688
<p>Abstract problem : I have a graph of about 250,000 nodes and the average connectivity is around 10. Finding a node's connections is a long process (10 seconds lets say). Saving a node to the database also takes about 10 seconds. I can check if a node is already present in the db very quickly. Allowing concurrency, b...
11
2009-08-24T06:05:32Z
1,320,714
<p>I am really confused as to why it takes 10 seconds to add a node to the DB. That sounds like a problem. What database are you using? Do you have severe platform restrictions?</p> <p>With modern systems, and their oodles of memory, I would recommend a nice simple cache of some kind. You should be able to create a ve...
2
2009-08-24T06:15:06Z
[ "python", "performance", "algorithm", "language-agnostic", "graph-traversal" ]
Good graph traversal algorithm
1,320,688
<p>Abstract problem : I have a graph of about 250,000 nodes and the average connectivity is around 10. Finding a node's connections is a long process (10 seconds lets say). Saving a node to the database also takes about 10 seconds. I can check if a node is already present in the db very quickly. Allowing concurrency, b...
11
2009-08-24T06:05:32Z
1,320,716
<p>To remember IDs of the users you've already visited, you need a map of a length of 250,000 integers. That's far from "too much". Just maintain such a map and only traverse through the edges that lead to the already undiscovered users, adding them to that map at the point of finding such edge.</p> <p>As far I can ...
7
2009-08-24T06:15:54Z
[ "python", "performance", "algorithm", "language-agnostic", "graph-traversal" ]
Good graph traversal algorithm
1,320,688
<p>Abstract problem : I have a graph of about 250,000 nodes and the average connectivity is around 10. Finding a node's connections is a long process (10 seconds lets say). Saving a node to the database also takes about 10 seconds. I can check if a node is already present in the db very quickly. Allowing concurrency, b...
11
2009-08-24T06:05:32Z
1,320,755
<p>There is no particular algorithm that will help you optimise the construction of a graph from scratch. One way or another, you are going to have to visit each node at least once. Whether you do this <a href="http://en.wikipedia.org/wiki/Depth-first%5Fsearch" rel="nofollow">depth first</a> or <a href="http://en.wikip...
2
2009-08-24T06:30:09Z
[ "python", "performance", "algorithm", "language-agnostic", "graph-traversal" ]
Good graph traversal algorithm
1,320,688
<p>Abstract problem : I have a graph of about 250,000 nodes and the average connectivity is around 10. Finding a node's connections is a long process (10 seconds lets say). Saving a node to the database also takes about 10 seconds. I can check if a node is already present in the db very quickly. Allowing concurrency, b...
11
2009-08-24T06:05:32Z
1,320,846
<p>Although you say that getting a friend list takes a lot of time (10 seconds or more), a variant of good-old Dijkstra's algorithm just might work:</p> <ol> <li>Get any node.</li> <li>Get a connection from any node you already loaded.</li> <li>If the other end hasn't been loaded yet, add the node to the graph.</li> <...
0
2009-08-24T07:04:43Z
[ "python", "performance", "algorithm", "language-agnostic", "graph-traversal" ]
Count number of files with certain extension in Python
1,320,731
<p>I am fairly new to Python and I am trying to figure out the most efficient way to count the number of .TIF files in a particular sub-directory.</p> <p>Doing some searching, I found one example (I have not tested), which claimed to count all of the files in a directory:</p> <pre><code>file_count = sum((len(f) for _...
16
2009-08-24T06:20:54Z
1,320,739
<p>Your code is fine. </p> <p>Yes, you're going to need to loop over those files to filter out the .tif files, but looping over a small in-memory array is negligible compared to the work of scanning the file directory to find these files in the first place, which you have to do anyway.</p> <p>I wouldn't worry about...
4
2009-08-24T06:24:47Z
[ "python", "file", "count" ]
Count number of files with certain extension in Python
1,320,731
<p>I am fairly new to Python and I am trying to figure out the most efficient way to count the number of .TIF files in a particular sub-directory.</p> <p>Doing some searching, I found one example (I have not tested), which claimed to count all of the files in a directory:</p> <pre><code>file_count = sum((len(f) for _...
16
2009-08-24T06:20:54Z
1,320,744
<p>Something has to iterate over all files in the directory, and look at every single file name - whether that's your code or a library routine. So no matter what the specific solution, they will all have roughly the same cost.</p> <p>If you think it's too much code, and if you don't actually need to search subdirecto...
23
2009-08-24T06:26:35Z
[ "python", "file", "count" ]
Count number of files with certain extension in Python
1,320,731
<p>I am fairly new to Python and I am trying to figure out the most efficient way to count the number of .TIF files in a particular sub-directory.</p> <p>Doing some searching, I found one example (I have not tested), which claimed to count all of the files in a directory:</p> <pre><code>file_count = sum((len(f) for _...
16
2009-08-24T06:20:54Z
1,320,780
<p>If you do need to search recursively, or for some other reason don't want to use the <code>glob</code> module, you could use</p> <pre><code>file_count = sum(len(f for f in fs if f.lower().endswith('.tif')) for _, _, fs in os.walk(myPath)) </code></pre> <p>This is the "Pythonic" way to adapt the example you found f...
2
2009-08-24T06:39:08Z
[ "python", "file", "count" ]
Count number of files with certain extension in Python
1,320,731
<p>I am fairly new to Python and I am trying to figure out the most efficient way to count the number of .TIF files in a particular sub-directory.</p> <p>Doing some searching, I found one example (I have not tested), which claimed to count all of the files in a directory:</p> <pre><code>file_count = sum((len(f) for _...
16
2009-08-24T06:20:54Z
1,321,138
<p>For this particular use case, if you don't want to recursively search in the subdirectory, you can use <code>os.listdir</code>:</p> <pre><code>len([f for f in os.listdir(myPath) if f.endswith('.tif') and os.path.isfile(os.path.join(myPath, f))]) </code></pre>
3
2009-08-24T08:33:22Z
[ "python", "file", "count" ]
Detect and delete locked file in python
1,320,812
<p>I want to detect whether a file is locked, using python on Unix. It's OK to delete the file, assuming that it helps detects whether the file was locked.</p> <p>The file could have been originally opened exclusively by another process. Documentation seems to suggest that os.unlink won't necessarily return an error i...
3
2009-08-24T06:51:04Z
1,320,880
<p>From the <a href="http://docs.python.org/library/fcntl.html" rel="nofollow">fcntl</a> docs:</p> <blockquote> <p>fcntl.lockf(fd, operation[, length[, start[, whence]]])</p> <p>If LOCK_NB is used and the lock cannot be acquired, an IOError will be raised and the exception will have an errno attribute set to EA...
6
2009-08-24T07:14:24Z
[ "python" ]
Detect and delete locked file in python
1,320,812
<p>I want to detect whether a file is locked, using python on Unix. It's OK to delete the file, assuming that it helps detects whether the file was locked.</p> <p>The file could have been originally opened exclusively by another process. Documentation seems to suggest that os.unlink won't necessarily return an error i...
3
2009-08-24T06:51:04Z
1,321,060
<p>The best way to check if a file is locked is to try to lock it. The <a href="http://docs.python.org/library/fcntl.html">fcntl module</a> will do this in Python, e.g.</p> <p><code>fcntl.lockf(fileobj.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)</code></p> <p>This will raise an IOError if the file is already locked; if ...
6
2009-08-24T08:12:00Z
[ "python" ]
How to start a COM server implemented in python?
1,320,954
<p>I am using python for making a COM local server. In fact, the whole COM part is implemented in a dll and my python script is calling that dll thanks to ctypes. It works ok when I run the script manually.</p> <p>I would like to see my server automatically ran when a COM client request it. I know that it is possible ...
1
2009-08-24T07:41:53Z
1,321,024
<p>The "-embedding" flag is <a href="http://msdn.microsoft.com/en-us/library/aa908849.aspx" rel="nofollow">added by COM automatically</a>, the purpose of which is so that the server application can parse this flag to determine that it was run by COM.</p> <blockquote> <p>COM appends the "-Embedding" flag to the str...
0
2009-08-24T08:02:00Z
[ "python", "windows", "com" ]
How to extend distutils with a simple post install script?
1,321,270
<p>I need to run a simple script after the modules and programs have been installed. I'm having a little trouble finding straight-forward documentation on how to do this. It looks like I need to inherit from distutils.command.install, override some methods and add this object to the setup script. The specifics are a bi...
33
2009-08-24T09:11:33Z
1,321,345
<p>I dug through distutils source for a day to learn enough about it to make a bunch of custom commands. It's not pretty, but it does work.</p> <pre><code>import distutils.core from distutils.command.install import install ... class my_install(install): def run(self): install.run(self) # Custom stu...
28
2009-08-24T09:27:59Z
[ "python", "distutils" ]
How to extend distutils with a simple post install script?
1,321,270
<p>I need to run a simple script after the modules and programs have been installed. I'm having a little trouble finding straight-forward documentation on how to do this. It looks like I need to inherit from distutils.command.install, override some methods and add this object to the setup script. The specifics are a bi...
33
2009-08-24T09:11:33Z
1,321,356
<p>OK, I figured it out. The idea is basically to extend one of the distutils commands and overwrite the run method. To tell distutils to use the new class you can use the cmdclass variable.</p> <pre><code>from distutils.core import setup from distutils.command.install_data import install_data class post_install(inst...
12
2009-08-24T09:31:05Z
[ "python", "distutils" ]
How to extend distutils with a simple post install script?
1,321,270
<p>I need to run a simple script after the modules and programs have been installed. I'm having a little trouble finding straight-forward documentation on how to do this. It looks like I need to inherit from distutils.command.install, override some methods and add this object to the setup script. The specifics are a bi...
33
2009-08-24T09:11:33Z
11,134,662
<p>I couldn't make <a href="http://stackoverflow.com/a/1321345/572616">Joe Wreschnig</a>s answer work and tweaked his answer analogous to the extending distutils <a href="http://docs.python.org/distutils/extending.html">documentation</a>. I came up with this code which works fine on my machine.</p> <pre><code>from dis...
5
2012-06-21T08:53:00Z
[ "python", "distutils" ]
How to extend distutils with a simple post install script?
1,321,270
<p>I need to run a simple script after the modules and programs have been installed. I'm having a little trouble finding straight-forward documentation on how to do this. It looks like I need to inherit from distutils.command.install, override some methods and add this object to the setup script. The specifics are a bi...
33
2009-08-24T09:11:33Z
19,677,464
<p>I got an error when I tried the accepted answer here (might be because I'm using Python 2.6 in this particular case, not sure). This occurred for both 'setup.py install' and 'pip install':</p> <pre><code>sudo python setup.py install </code></pre> <p>fails with <em>error: error in setup.cfg: command 'my_install' ha...
-1
2013-10-30T08:41:04Z
[ "python", "distutils" ]
What are the required functionnalities of ETL frameworks?
1,321,396
<p>I am writing an ETL (in python with a mongodb backend) and was wondering : what kind of standard functions and tools an ETL should have to be called an ETL ? </p> <p>This ETL will be as general purpose as possible, with a scriptable and modular approach. Mostly it will be used to keep different databases in sync, a...
11
2009-08-24T09:41:16Z
1,321,429
<p>Here's a random list, in no particular order:</p> <ol> <li>Connect to a wide range of sources, including all the major relational databases.</li> <li>Handle non-relational data sources like text files, Excel, XML, etc.</li> <li>Allow multiple sources to be mapped into a single target.</li> <li>Provide a tool to hel...
4
2009-08-24T09:49:33Z
[ "python", "mongodb", "etl" ]
What are the required functionnalities of ETL frameworks?
1,321,396
<p>I am writing an ETL (in python with a mongodb backend) and was wondering : what kind of standard functions and tools an ETL should have to be called an ETL ? </p> <p>This ETL will be as general purpose as possible, with a scriptable and modular approach. Mostly it will be used to keep different databases in sync, a...
11
2009-08-24T09:41:16Z
1,321,585
<p>Let's think of the ETL use cases for a moment.</p> <ol> <li>Extract. <ul> <li>Read databases through a generic DB-API adapter.</li> <li>Read flat files through a similar adapter.</li> <li>Read spreadsheets through a similar adapter.</li> </ul></li> <li>Cleanse. <ul> <li>Arbitrary rules</li> <li>Filter and reject</l...
16
2009-08-24T10:26:51Z
[ "python", "mongodb", "etl" ]
What are the required functionnalities of ETL frameworks?
1,321,396
<p>I am writing an ETL (in python with a mongodb backend) and was wondering : what kind of standard functions and tools an ETL should have to be called an ETL ? </p> <p>This ETL will be as general purpose as possible, with a scriptable and modular approach. Mostly it will be used to keep different databases in sync, a...
11
2009-08-24T09:41:16Z
1,321,885
<p>Automatic / heuristic mapping of column names. E.g simple string mappings:</p> <p>DB1: customerId</p> <p>DB2: customer_id</p> <p>I find a lot of the work I (have) done in DTS / SSIS could've been automatically generated.</p> <ul> <li>not necessarily "required functionality", but would keep a lot of your users ve...
0
2009-08-24T11:38:42Z
[ "python", "mongodb", "etl" ]
How to use the same widget twice in pygtk?
1,321,655
<p>This doesn't work well:</p> <pre><code> image_log = gtk.Image() image_log.set_from_file("test.png") self.out_button = gtk.Button() self.out_button.add(image_log) self.err_button = gtk.Button() self.err_button.add(image_log) another_box.pack_start(self.out_button, False) another_box...
2
2009-08-24T10:46:59Z
1,321,678
<p>Why not</p> <pre><code>image_log = gtk.Image() image_log.set_from_file("test.png") image_logb = gtk.Image() image_logb.set_from_file("test.png") self.out_button = gtk.Button() self.out_button.add(image_log) self.err_button = gtk.Button() self.err_button.add(image_logb) another_box.pack_start(self.out_button, Fal...
1
2009-08-24T10:50:49Z
[ "python", "widget", "pygtk" ]
How to use the same widget twice in pygtk?
1,321,655
<p>This doesn't work well:</p> <pre><code> image_log = gtk.Image() image_log.set_from_file("test.png") self.out_button = gtk.Button() self.out_button.add(image_log) self.err_button = gtk.Button() self.err_button.add(image_log) another_box.pack_start(self.out_button, False) another_box...
2
2009-08-24T10:46:59Z
1,321,714
<p>You could use a factory function to reduce code duplication</p> <pre><code>def make_image_from_file(fname): im = gtk.Image() im.set_from_file(fname) return im self.out_button.set_image(make_image_from_file(..)) </code></pre> <h1>Revisiting</h1> <p>There is a much more natural way. You will like it. In PyGT...
2
2009-08-24T10:59:29Z
[ "python", "widget", "pygtk" ]
How to use the same widget twice in pygtk?
1,321,655
<p>This doesn't work well:</p> <pre><code> image_log = gtk.Image() image_log.set_from_file("test.png") self.out_button = gtk.Button() self.out_button.add(image_log) self.err_button = gtk.Button() self.err_button.add(image_log) another_box.pack_start(self.out_button, False) another_box...
2
2009-08-24T10:46:59Z
6,002,963
<p>Use</p> <pre><code>def clone_widget(widget): widget2=widget.__class__() for prop in dir(widget): if prop.startswith("set_") and prop not in ["set_buffer"]: prop_value=None try: prop_value=getattr(widget, prop.replace("set_","get_") )() ...
2
2011-05-14T15:53:37Z
[ "python", "widget", "pygtk" ]
Grant anonymous access to a specific url/action in Plone
1,321,828
<p>I am running Plone 3.2.3 and I have installed <a href="http://plone.org/products/humainemailman/releases/1.0" rel="nofollow">HumaineMailman</a> so that the users on the website can subscribe and unsubscribe themselves from our various mailinglists. HumaineMailman works very simple. There is a special URL/action that...
0
2009-08-24T11:24:08Z
1,322,115
<p>Figure out what permission is protecting that page, and give that permission to the Anonymous role in the Plone root.</p>
1
2009-08-24T12:35:37Z
[ "python", "plone", "zope", "mailman" ]
Grant anonymous access to a specific url/action in Plone
1,321,828
<p>I am running Plone 3.2.3 and I have installed <a href="http://plone.org/products/humainemailman/releases/1.0" rel="nofollow">HumaineMailman</a> so that the users on the website can subscribe and unsubscribe themselves from our various mailinglists. HumaineMailman works very simple. There is a special URL/action that...
0
2009-08-24T11:24:08Z
1,322,933
<p>HumaineMailman needs ManagePortal permissions. Those are too much to give to Anonymous so Lennarts answer didn't solve it for me. Instead, I edited HumaineMailman and redeclared the respective function calls as public. This is a slight security risk though. My Plone is behind an Apache proxy so I compensated by only...
0
2009-08-24T15:03:49Z
[ "python", "plone", "zope", "mailman" ]
Grant anonymous access to a specific url/action in Plone
1,321,828
<p>I am running Plone 3.2.3 and I have installed <a href="http://plone.org/products/humainemailman/releases/1.0" rel="nofollow">HumaineMailman</a> so that the users on the website can subscribe and unsubscribe themselves from our various mailinglists. HumaineMailman works very simple. There is a special URL/action that...
0
2009-08-24T11:24:08Z
1,413,867
<p>There are a couple ways to address this without apache or redeclaring security (which would make me nervous too)</p> <pre><code>http://www.example.org:8080/mailman_autolist_update?list=mylist@example.org&amp;password=secret&amp;__ac_name=**USERNAME**&amp;__ac_password=**PASSWORD**&amp;pwd_empty=0&amp;cookies_enable...
2
2009-09-12T00:36:39Z
[ "python", "plone", "zope", "mailman" ]
Vim python's buffer.append(line) switch window's focus
1,321,936
<p>I am trying to fill Vim's buffer from separate thread by using this python code.</p> <pre><code>python &lt;&lt; PYTHON_CODE import vim import time buffer_number = -1 class AppendLineTest( Thread ): def run(self): buffer = vim.buffers[buffer_number - 1] for i in range(10): buffer.append('L...
2
2009-08-24T11:58:43Z
1,322,007
<p>I don't think Vim is very tolerant of multiple threads without patching. There's a lot more detail in the discussion <a href="http://groups.google.com/group/vim%5Fdev/browse%5Fthread/thread/0c7fc4b78bd62c92?pli=1" rel="nofollow">at this link</a>, but I suspect that what you want is far from trivial.</p>
2
2009-08-24T12:15:37Z
[ "python", "vim", "plugins" ]
Is it possible to use Panda3D inside a wxPython app?
1,322,041
<p>I'm developing a wxPython application. Will it be possible to embed a 3D animation controlled by Panda3D inside the gui?</p> <p>Bonus question: Do you think that Panda3D is the best choice? (My interest is physical simulations, and no, I don't need an engine that supports Physics, my program is responsible for calc...
6
2009-08-24T12:21:46Z
1,323,506
<p>Yes - the Panda3D wiki has a mention of <a href="http://www.panda3d.org/wiki/index.php/Main%5FLoop" rel="nofollow">using wxPython to handle GUI duties</a>.</p> <p>There's also some threads on the Panda3D forum (<a href="http://www.panda3d.org/phpbb2/viewtopic.php?t=2397" rel="nofollow">1</a>, <a href="http://www.pa...
3
2009-08-24T16:48:48Z
[ "python", "3d", "wxpython" ]
to restrict parameter values strictly with in bounds
1,322,049
<p>I am trying to optimize a function using l_bfgs constraint optimization routine in scipy. But the optimization routine passes values to the function, which are not with in the Bounds.</p> <p>my full code looks like,</p> <pre><code>def humpy(aParams): aParams = numpy.asarray(aParams) print aParams #### # connec...
0
2009-08-24T12:23:20Z
1,322,244
<p>You are trying to do bitwise exclusive or (the ^ operator) on floats, which makes no sense, so I don't think your code is actually the code you have problems with. However, I changed the ^ to ** assuming that was what you meant, and had no problems. The code worked fine for me with that change. The parameters are re...
1
2009-08-24T12:57:54Z
[ "python", "scipy" ]
to restrict parameter values strictly with in bounds
1,322,049
<p>I am trying to optimize a function using l_bfgs constraint optimization routine in scipy. But the optimization routine passes values to the function, which are not with in the Bounds.</p> <p>my full code looks like,</p> <pre><code>def humpy(aParams): aParams = numpy.asarray(aParams) print aParams #### # connec...
0
2009-08-24T12:23:20Z
1,322,413
<p>Are you asking about doing something like this?</p> <pre><code>def humpy(aParams): aParams = numpy.asarray(aParams) x = aParams[0] y = aParams[1] z = aParams[2] u = aParams[3] v = aParams[4] assert 2 &lt;= x &lt;= 50000 assert 1 &lt;= y &lt;= 35000 assert 1 &lt;= z &lt;= 45000 assert 2 &lt;= u &...
0
2009-08-24T13:28:06Z
[ "python", "scipy" ]
Determine if Python variable is an instance of a built-in type
1,322,068
<p>I need to determine if a given Python variable is an instance of native type: <code>str</code>, <code>int</code>, <code>float</code>, <code>bool</code>, <code>list</code>, <code>dict</code> and so on. Is there elegant way to doing it?</p> <p>Or is this the only way: </p> <pre><code>if myvar in (str, int, float, bo...
11
2009-08-24T12:27:22Z
1,322,086
<p>Built in type function may be helpful:</p> <pre><code>&gt;&gt;&gt; a = 5 &gt;&gt;&gt; type(a) &lt;type 'int'&gt; </code></pre>
1
2009-08-24T12:31:27Z
[ "python", "variables", "instance" ]
Determine if Python variable is an instance of a built-in type
1,322,068
<p>I need to determine if a given Python variable is an instance of native type: <code>str</code>, <code>int</code>, <code>float</code>, <code>bool</code>, <code>list</code>, <code>dict</code> and so on. Is there elegant way to doing it?</p> <p>Or is this the only way: </p> <pre><code>if myvar in (str, int, float, bo...
11
2009-08-24T12:27:22Z
1,322,090
<p>What is a "native type" in Python? Please don't base your code on types, use <a href="http://en.wikipedia.org/wiki/Duck%5FTyping" rel="nofollow">Duck Typing</a>.</p>
2
2009-08-24T12:31:47Z
[ "python", "variables", "instance" ]
Determine if Python variable is an instance of a built-in type
1,322,068
<p>I need to determine if a given Python variable is an instance of native type: <code>str</code>, <code>int</code>, <code>float</code>, <code>bool</code>, <code>list</code>, <code>dict</code> and so on. Is there elegant way to doing it?</p> <p>Or is this the only way: </p> <pre><code>if myvar in (str, int, float, bo...
11
2009-08-24T12:27:22Z
1,322,099
<p>Not that I know why you would want to do it, as there isn't any "simple" types in Python, it's all objects. But this works:</p> <pre><code>type(theobject).__name__ in dir(__builtins__) </code></pre> <p>But explicitly listing the types is probably better as it's clearer. Or even better: Changing the application so ...
5
2009-08-24T12:32:47Z
[ "python", "variables", "instance" ]
Determine if Python variable is an instance of a built-in type
1,322,068
<p>I need to determine if a given Python variable is an instance of native type: <code>str</code>, <code>int</code>, <code>float</code>, <code>bool</code>, <code>list</code>, <code>dict</code> and so on. Is there elegant way to doing it?</p> <p>Or is this the only way: </p> <pre><code>if myvar in (str, int, float, bo...
11
2009-08-24T12:27:22Z
1,322,152
<p>The best way to achieve this is to collect the types in a list of tuple called <code>primitiveTypes</code> and:</p> <pre><code>if isinstance(myvar, primitiveTypes): ... </code></pre> <p>The <a href="http://docs.python.org/library/types.html" rel="nofollow"><code>types</code> module</a> contains collections of all ...
10
2009-08-24T12:42:49Z
[ "python", "variables", "instance" ]
Determine if Python variable is an instance of a built-in type
1,322,068
<p>I need to determine if a given Python variable is an instance of native type: <code>str</code>, <code>int</code>, <code>float</code>, <code>bool</code>, <code>list</code>, <code>dict</code> and so on. Is there elegant way to doing it?</p> <p>Or is this the only way: </p> <pre><code>if myvar in (str, int, float, bo...
11
2009-08-24T12:27:22Z
1,322,311
<p>You appear to be interested in assuring the simplejson will handle your types. This is done trivially by </p> <pre><code>try: json.dumps( object ) except TypeError: print "Can't convert", object </code></pre> <p>Which is more reliable than trying to guess which types your JSON implementation handles.</p>
6
2009-08-24T13:08:58Z
[ "python", "variables", "instance" ]
Determine if Python variable is an instance of a built-in type
1,322,068
<p>I need to determine if a given Python variable is an instance of native type: <code>str</code>, <code>int</code>, <code>float</code>, <code>bool</code>, <code>list</code>, <code>dict</code> and so on. Is there elegant way to doing it?</p> <p>Or is this the only way: </p> <pre><code>if myvar in (str, int, float, bo...
11
2009-08-24T12:27:22Z
1,325,236
<p>building off of S.Lott's answer you should have something like this:</p> <pre><code> from simplejson import JSONEncoder class JSONEncodeAll(JSONEncoder): def default(self, obj): try: return JSONEncoder.default(self, obj) except TypeError: ## optionally # try: # # you'd have to a...
0
2009-08-24T23:00:24Z
[ "python", "variables", "instance" ]
Determine if Python variable is an instance of a built-in type
1,322,068
<p>I need to determine if a given Python variable is an instance of native type: <code>str</code>, <code>int</code>, <code>float</code>, <code>bool</code>, <code>list</code>, <code>dict</code> and so on. Is there elegant way to doing it?</p> <p>Or is this the only way: </p> <pre><code>if myvar in (str, int, float, bo...
11
2009-08-24T12:27:22Z
17,795,199
<p>This is an old question but it seems none of the answers actually answer the specific question: "(How-to) Determine if Python variable is an instance of a built-in type". Note that it's not "[...] of a <strong>specific/given</strong> built-in type" but of <strong>a</strong>.</p> <p>The proper way to <em>determine i...
4
2013-07-22T18:52:30Z
[ "python", "variables", "instance" ]
Determine if Python variable is an instance of a built-in type
1,322,068
<p>I need to determine if a given Python variable is an instance of native type: <code>str</code>, <code>int</code>, <code>float</code>, <code>bool</code>, <code>list</code>, <code>dict</code> and so on. Is there elegant way to doing it?</p> <p>Or is this the only way: </p> <pre><code>if myvar in (str, int, float, bo...
11
2009-08-24T12:27:22Z
29,275,079
<p>you can access all these types by <code>types</code> module:</p> <pre><code>`builtin_types = [ i for i in types.__dict__.values() if isinstance(i, type)]` </code></pre> <p>as a reminder, import module <code>types</code> first</p> <pre><code>def isBuiltinTypes(var): return type(var) in [i for i in types.__di...
1
2015-03-26T09:35:34Z
[ "python", "variables", "instance" ]
gotchas where Numpy differs from straight python?
1,322,380
<p>Folks,</p> <p>is there a collection of gotchas where Numpy differs from python, points that have puzzled and cost time ?</p> <blockquote> <p>"The horror of that moment I shall never never forget !"<br /> "You will, though," the Queen said, "if you don't make a memorandum of it."</p> </blockquote> <p>For e...
23
2009-08-24T13:21:37Z
1,322,431
<pre><code>print pynan is pynan, pynan is NaN, NaN is NaN </code></pre> <p>This tests identity, that is if it is the same object. The result should therefore obviously be True, False, True, because when you do float(whatever) you are creating a new float object.</p> <pre><code>a = (0, pynan) print a, a[1] is pynan, a...
3
2009-08-24T13:31:25Z
[ "python", "numpy" ]
gotchas where Numpy differs from straight python?
1,322,380
<p>Folks,</p> <p>is there a collection of gotchas where Numpy differs from python, points that have puzzled and cost time ?</p> <blockquote> <p>"The horror of that moment I shall never never forget !"<br /> "You will, though," the Queen said, "if you don't make a memorandum of it."</p> </blockquote> <p>For e...
23
2009-08-24T13:21:37Z
1,322,468
<p><code>NaN</code> is not a singleton like <code>None</code>, so you can't really use the is check on it. What makes it a bit tricky is that <code>NaN == NaN</code> is <code>False</code> as IEEE-754 requires. That's why you need to use the <code>numpy.isnan()</code> function to check if a float is not a number. Or the...
12
2009-08-24T13:36:41Z
[ "python", "numpy" ]
gotchas where Numpy differs from straight python?
1,322,380
<p>Folks,</p> <p>is there a collection of gotchas where Numpy differs from python, points that have puzzled and cost time ?</p> <blockquote> <p>"The horror of that moment I shall never never forget !"<br /> "You will, though," the Queen said, "if you don't make a memorandum of it."</p> </blockquote> <p>For e...
23
2009-08-24T13:21:37Z
1,323,233
<p>I think this one is funny:</p> <pre><code>&gt;&gt;&gt; import numpy as n &gt;&gt;&gt; a = n.array([[1,2],[3,4]]) &gt;&gt;&gt; a[1], a[0] = a[0], a[1] &gt;&gt;&gt; a array([[1, 2], [1, 2]]) </code></pre> <p>For Python lists on the other hand this works as intended:</p> <pre><code>&gt;&gt;&gt; b = [[1,2],[3,...
20
2009-08-24T15:58:42Z
[ "python", "numpy" ]
gotchas where Numpy differs from straight python?
1,322,380
<p>Folks,</p> <p>is there a collection of gotchas where Numpy differs from python, points that have puzzled and cost time ?</p> <blockquote> <p>"The horror of that moment I shall never never forget !"<br /> "You will, though," the Queen said, "if you don't make a memorandum of it."</p> </blockquote> <p>For e...
23
2009-08-24T13:21:37Z
1,324,939
<p>The biggest gotcha for me was that almost every standard operator is overloaded to distribute across the array.</p> <p>Define a list and an array</p> <pre><code>&gt;&gt;&gt; l = range(10) &gt;&gt;&gt; l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] &gt;&gt;&gt; import numpy &gt;&gt;&gt; a = numpy.array(l) &gt;&gt;&gt; a array([0...
19
2009-08-24T21:44:02Z
[ "python", "numpy" ]
gotchas where Numpy differs from straight python?
1,322,380
<p>Folks,</p> <p>is there a collection of gotchas where Numpy differs from python, points that have puzzled and cost time ?</p> <blockquote> <p>"The horror of that moment I shall never never forget !"<br /> "You will, though," the Queen said, "if you don't make a memorandum of it."</p> </blockquote> <p>For e...
23
2009-08-24T13:21:37Z
1,411,629
<p>from Neil Martinsen-Burrell in <a href="http://mail.scipy.org/pipermail/numpy-discussion/2009-September/045041.html" rel="nofollow">numpy-discussion</a> 7 Sept --</p> <blockquote> <p>The ndarray type available in Numpy is not conceptually an extension of Python's iterables. If you'd like to help other Nu...
2
2009-09-11T15:30:19Z
[ "python", "numpy" ]
gotchas where Numpy differs from straight python?
1,322,380
<p>Folks,</p> <p>is there a collection of gotchas where Numpy differs from python, points that have puzzled and cost time ?</p> <blockquote> <p>"The horror of that moment I shall never never forget !"<br /> "You will, though," the Queen said, "if you don't make a memorandum of it."</p> </blockquote> <p>For e...
23
2009-08-24T13:21:37Z
1,413,996
<p>The truth value of a Numpy array differs from that of a python sequence type, where any non-empty sequence is true.</p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; l = [0,1,2,3] &gt;&gt;&gt; a = np.arange(4) &gt;&gt;&gt; if l: print "Im true" ... Im true &gt;&gt;&gt; if a: print "Im true" ... Tracebac...
6
2009-09-12T01:45:23Z
[ "python", "numpy" ]
gotchas where Numpy differs from straight python?
1,322,380
<p>Folks,</p> <p>is there a collection of gotchas where Numpy differs from python, points that have puzzled and cost time ?</p> <blockquote> <p>"The horror of that moment I shall never never forget !"<br /> "You will, though," the Queen said, "if you don't make a memorandum of it."</p> </blockquote> <p>For e...
23
2009-08-24T13:21:37Z
1,414,038
<p>Slicing creates views, not copies.</p> <pre><code>&gt;&gt;&gt; l = [1, 2, 3, 4] &gt;&gt;&gt; s = l[2:3] &gt;&gt;&gt; s[0] = 5 &gt;&gt;&gt; l [1, 2, 3, 4] &gt;&gt;&gt; a = array([1, 2, 3, 4]) &gt;&gt;&gt; s = a[2:3] &gt;&gt;&gt; s[0] = 5 &gt;&gt;&gt; a array([1, 2, 5, 4]) </code></pre>
7
2009-09-12T02:19:46Z
[ "python", "numpy" ]
gotchas where Numpy differs from straight python?
1,322,380
<p>Folks,</p> <p>is there a collection of gotchas where Numpy differs from python, points that have puzzled and cost time ?</p> <blockquote> <p>"The horror of that moment I shall never never forget !"<br /> "You will, though," the Queen said, "if you don't make a memorandum of it."</p> </blockquote> <p>For e...
23
2009-08-24T13:21:37Z
3,791,525
<p>I found the fact that multiplying up lists of elements just creates view of elements caught me out.</p> <pre><code>&gt;&gt;&gt; a=[0]*5 &gt;&gt;&gt;a [0,0,0,0,0] &gt;&gt;&gt;a[2] = 1 &gt;&gt;&gt;a [0,0,1,0,0] &gt;&gt;&gt;b = [np.ones(3)]*5 &gt;&gt;&gt;b [array([ 1., 1., 1.]), array([ 1., 1., 1.]), array([ 1., ...
2
2010-09-24T22:39:20Z
[ "python", "numpy" ]
gotchas where Numpy differs from straight python?
1,322,380
<p>Folks,</p> <p>is there a collection of gotchas where Numpy differs from python, points that have puzzled and cost time ?</p> <blockquote> <p>"The horror of that moment I shall never never forget !"<br /> "You will, though," the Queen said, "if you don't make a memorandum of it."</p> </blockquote> <p>For e...
23
2009-08-24T13:21:37Z
6,065,203
<p>Because <code>__eq__</code> does not return a bool, using numpy arrays in any kind of containers prevents equality testing without a container-specific work around.</p> <p>Example:</p> <pre><code>&gt;&gt;&gt; import numpy &gt;&gt;&gt; a = numpy.array(range(3)) &gt;&gt;&gt; b = numpy.array(range(3)) &gt;&gt;&gt; a ...
23
2011-05-19T21:43:35Z
[ "python", "numpy" ]
gotchas where Numpy differs from straight python?
1,322,380
<p>Folks,</p> <p>is there a collection of gotchas where Numpy differs from python, points that have puzzled and cost time ?</p> <blockquote> <p>"The horror of that moment I shall never never forget !"<br /> "You will, though," the Queen said, "if you don't make a memorandum of it."</p> </blockquote> <p>For e...
23
2009-08-24T13:21:37Z
6,876,084
<p>(Related, but a NumPy vs. SciPy gotcha, rather than NumPy vs Python)</p> <hr> <p>Slicing beyond an array's real size works differently:</p> <pre><code>&gt;&gt;&gt; import numpy, scipy.sparse &gt;&gt;&gt; m = numpy.random.rand(2, 5) # create a 2x5 dense matrix &gt;&gt;&gt; print m[:3, :] # works like list slicing...
5
2011-07-29T16:21:20Z
[ "python", "numpy" ]
gotchas where Numpy differs from straight python?
1,322,380
<p>Folks,</p> <p>is there a collection of gotchas where Numpy differs from python, points that have puzzled and cost time ?</p> <blockquote> <p>"The horror of that moment I shall never never forget !"<br /> "You will, though," the Queen said, "if you don't make a memorandum of it."</p> </blockquote> <p>For e...
23
2009-08-24T13:21:37Z
7,384,044
<p>Not such a big gotcha: With boolean slicing, I sometimes wish I could do </p> <pre><code> x[ 3 &lt;= y &lt; 7 ] </code></pre> <p>like the python double comparison. Instead, I have to write </p> <pre><code> x[ np.logical_and(3&lt;=y, y&lt;7) ] </code></pre> <p>(Unless you know something better?)</p> <p>Also,...
2
2011-09-12T06:26:24Z
[ "python", "numpy" ]
gotchas where Numpy differs from straight python?
1,322,380
<p>Folks,</p> <p>is there a collection of gotchas where Numpy differs from python, points that have puzzled and cost time ?</p> <blockquote> <p>"The horror of that moment I shall never never forget !"<br /> "You will, though," the Queen said, "if you don't make a memorandum of it."</p> </blockquote> <p>For e...
23
2009-08-24T13:21:37Z
14,986,289
<pre><code>In [1]: bool([]) Out[1]: False In [2]: bool(array([])) Out[2]: False In [3]: bool([0]) Out[3]: True In [4]: bool(array([0])) Out[4]: False </code></pre> <p>So don't test for the emptiness of an array by checking its truth value. Use <code>size(array())</code>.</p> <p>And don't use <code>len(array())</c...
6
2013-02-20T17:35:11Z
[ "python", "numpy" ]
gotchas where Numpy differs from straight python?
1,322,380
<p>Folks,</p> <p>is there a collection of gotchas where Numpy differs from python, points that have puzzled and cost time ?</p> <blockquote> <p>"The horror of that moment I shall never never forget !"<br /> "You will, though," the Queen said, "if you don't make a memorandum of it."</p> </blockquote> <p>For e...
23
2009-08-24T13:21:37Z
14,986,378
<p>No one seems to have mentioned this so far:</p> <pre><code>&gt;&gt;&gt; all(False for i in range(3)) False &gt;&gt;&gt; from numpy import all &gt;&gt;&gt; all(False for i in range(3)) True &gt;&gt;&gt; any(False for i in range(3)) False &gt;&gt;&gt; from numpy import any &gt;&gt;&gt; any(False for i in range(3)) Tr...
2
2013-02-20T17:39:45Z
[ "python", "numpy" ]