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 |
|---|---|---|---|---|---|---|---|---|---|
How can I use a DLL file from Python? | 252,417 | <p>What is the easiest way to use a DLL file from within Python?</p>
<p>Specifically, how can this be done <em>without</em> writing any additional wrapper C++ code to expose the functionality to Python?</p>
<p>Native Python functionality is strongly preferred over using a third-party library.</p>
| 105 | 2008-10-31T02:01:48Z | 252,438 | <p>ctypes can be used to access dlls, here's a tutorial:</p>
<p><a href="http://docs.python.org/library/ctypes.html#module-ctypes">http://docs.python.org/library/ctypes.html#module-ctypes</a></p>
| 6 | 2008-10-31T02:18:03Z | [
"python",
"dll"
] |
How can I use a DLL file from Python? | 252,417 | <p>What is the easiest way to use a DLL file from within Python?</p>
<p>Specifically, how can this be done <em>without</em> writing any additional wrapper C++ code to expose the functionality to Python?</p>
<p>Native Python functionality is strongly preferred over using a third-party library.</p>
| 105 | 2008-10-31T02:01:48Z | 252,444 | <p>ctypes will be the easiest thing to use but (mis)using it makes Python subject to crashing. If you are trying to do something quickly, and you are careful, it's great.</p>
<p>I would encourage you to check out <a href="http://www.boost.org/doc/libs/1_36_0/libs/python/doc/index.html" rel="nofollow">Boost Python</a>.... | 1 | 2008-10-31T02:24:51Z | [
"python",
"dll"
] |
How can I use a DLL file from Python? | 252,417 | <p>What is the easiest way to use a DLL file from within Python?</p>
<p>Specifically, how can this be done <em>without</em> writing any additional wrapper C++ code to expose the functionality to Python?</p>
<p>Native Python functionality is strongly preferred over using a third-party library.</p>
| 105 | 2008-10-31T02:01:48Z | 252,473 | <p>For ease of use, <a href="http://docs.python.org/library/ctypes.html">ctypes</a> is the way to go.</p>
<p>The following example of ctypes is from actual code I've written (in Python 2.5). This has been, by far, the easiest way I've found for doing what you ask.</p>
<pre><code>import ctypes
# Load DLL into memory... | 88 | 2008-10-31T02:43:41Z | [
"python",
"dll"
] |
How can I use a DLL file from Python? | 252,417 | <p>What is the easiest way to use a DLL file from within Python?</p>
<p>Specifically, how can this be done <em>without</em> writing any additional wrapper C++ code to expose the functionality to Python?</p>
<p>Native Python functionality is strongly preferred over using a third-party library.</p>
| 105 | 2008-10-31T02:01:48Z | 3,173,926 | <p><a href="http://web.archive.org/web/20111006042404/http://www.knowledgetantra.com/component/content/article/2-python/1-call-dll-function-in-python.html">This page</a> is a very simple example of calling functions from a DLL file.</p>
<blockquote>
<p>It's very easy to call a DLL function in Python. I have a self-m... | 32 | 2010-07-04T06:28:31Z | [
"python",
"dll"
] |
How can I use a DLL file from Python? | 252,417 | <p>What is the easiest way to use a DLL file from within Python?</p>
<p>Specifically, how can this be done <em>without</em> writing any additional wrapper C++ code to expose the functionality to Python?</p>
<p>Native Python functionality is strongly preferred over using a third-party library.</p>
| 105 | 2008-10-31T02:01:48Z | 17,157,302 | <p>Maybe with <code>Dispatch</code>:</p>
<pre><code>from win32com.client import Dispatch
zk = Dispatch("zkemkeeper.ZKEM")
</code></pre>
<p>Where zkemkeeper is a registered DLL file on the system...
After that, you can access functions just by calling them:</p>
<pre><code>zk.Connect_Net(IP_address, port)
</code></p... | 1 | 2013-06-17T21:38:07Z | [
"python",
"dll"
] |
Why won't Django 1.0 admin application work? | 252,531 | <p>I've just started playing with Django and am loosely following the tutorial with my own set of basic requirements. The models I've sketched out so far are a lot more comprehensive than the tutorial, but they compile fine. Otherwise, everything should have been the same.</p>
<p>My problem is with the admin applicati... | 5 | 2008-10-31T03:35:19Z | 252,621 | <p>It's because you left out a <code>/</code> in <code>urls.py</code>. Change the admin line to the following:</p>
<pre><code>(r'^admin/(.*)', admin.site.root),
</code></pre>
<p>I checked this on my server and got the same error with your line from <code>urls.py</code>.</p>
| 12 | 2008-10-31T04:50:27Z | [
"python",
"django",
"admin"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 252,704 | <p><code>append</code> appends a single element. <code>extend</code> appends a list of elements.</p>
<p>Note that if you pass a list to append, it still adds one element:</p>
<pre><code>>>> a = [1, 2, 3]
>>> a.append([4, 5, 6])
>>> a
[1, 2, 3, [4, 5, 6]]
</code></pre>
| 72 | 2008-10-31T05:57:32Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 252,705 | <p><code>append</code> adds an element to a list, <code>extend</code> concatenates the first list with another list (or another iterable not necessarily a list.)</p>
<pre><code>>>> li = ['a', 'b', 'mpilgrim', 'z', 'example']
>>> li
['a', 'b', 'mpilgrim', 'z', 'example']
>>> li.append("new")... | 388 | 2008-10-31T05:57:37Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 252,711 | <p><a href="https://docs.python.org/2/library/array.html?#array.array.append"><code>append</code></a>: Appends object at end.</p>
<pre><code>x = [1, 2, 3]
x.append([4, 5])
print (x)
</code></pre>
<p>gives you: <code>[1, 2, 3, [4, 5]]</code></p>
<hr>
<p><a href="https://docs.python.org/2/library/array.html?#array.ar... | 2,392 | 2008-10-31T06:02:25Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 252,918 | <p>Good answers, but don't forget, any iterable will do for <code>extend</code> (not just list):</p>
<pre><code>l.extend(xrange(5))
</code></pre>
| 50 | 2008-10-31T09:03:22Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 262,132 | <p>And in this context it can also be good to remember that strings are also iterable.</p>
<pre><code>>>> a = [1, 2]
>>> a
[1, 2]
>>> a.extend('hey')
>>> a
[1, 2, 'h', 'e', 'y']
</code></pre>
| 197 | 2008-11-04T15:19:52Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 5,605,403 | <p>Like <code>Ali A</code> said, any iterable will do for the extend,
here is an example for dictionary argument,</p>
<pre><code>>>> li=[1,2,3]
>>> li.extend({4:5,6:7})
>>> li
[1, 2, 3, 4, 6]
>>>
</code></pre>
<p>as you can see, only <code>keys</code> are added to the list.</p>
| 31 | 2011-04-09T13:46:02Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 12,045,242 | <p>The following two snippets are semantically equivalent:</p>
<pre><code> for item in iterator:
a_list.append(item)
</code></pre>
<p>and</p>
<pre><code>a_list.extend(iterator)
</code></pre>
<p>The latter may be faster as the loop is implemented in C.</p>
| 28 | 2012-08-20T21:11:00Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 16,510,635 | <p><code>extend()</code> can be used with an iterator argument. Here is an example. You wish to make a list out of a list of lists this way:</p>
<p>from</p>
<pre><code>list2d = [[1,2,3],[4,5,6], [7], [8,9]]
</code></pre>
<p>you want</p>
<pre><code>>>>
[1, 2, 3, 4, 5, 6, 7, 8, 9]
</code></pre>
<p>You may ... | 10 | 2013-05-12T18:21:40Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 16,511,403 | <p>append(object) - Updates the list by adding an object to the list.</p>
<pre><code>x = [20]
# list passed to the append(object) method is treated as a single object.
x.append([21,22,23])
#hence the resultant list length will be 2
print x
--> [20, [21,22,23]]
</code></pre>
<p>extend(list) - Essentially concaten... | 10 | 2013-05-12T19:51:07Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 18,442,908 | <p>You can use "+" for returning extend, instead of extending in place.</p>
<pre><code>l1=range(10)
l1+[11]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11]
l2=range(10,1,-1)
l1+l2
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2]
</code></pre>
<p>Similarly <code>+=</code> for in place behavior, but with slight diffe... | 20 | 2013-08-26T11:21:12Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 19,707,477 | <p>The append() method adds a single item to the end of the list. </p>
<pre><code>x = [1, 2, 3]
x.append([4, 5])
x.append('abc')
print x
# gives you
[1, 2, 3, [4, 5], 'abc']
</code></pre>
<p>The extend() method takes one argument, a list, and appends each of the items of the argument to the original list. (Lists are ... | 22 | 2013-10-31T13:12:10Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 24,632,188 | <p>This is the equivalent of <code>append</code> and <code>extend</code> using the <code>+</code> operator:</p>
<pre><code>>>> x = [1,2,3]
>>> x
[1, 2, 3]
>>> x = x + [4,5,6] # Extend
>>> x
[1, 2, 3, 4, 5, 6]
>>> x = x + [[7,8]] # Append
>>> x
[1, 2, 3, 4, 5, 6, [7... | 8 | 2014-07-08T12:42:52Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 25,144,368 | <p>An interesting point that has been hinted, but not explained, is that extend is faster than append. For any loop that has append inside should be considered to be replaced by list.extend(processed_elements).</p>
<p>Bear in mind that apprending new elements might result in the realloaction of the whole list to a bet... | 5 | 2014-08-05T16:58:25Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 25,920,729 | <pre><code>list1 = [1,2,3,4,5]
list2 = ["a","b","c","d","e"]
</code></pre>
<p>append:</p>
<pre><code>print list.append(list2)
</code></pre>
<p>output : [1,2,3,4,5,["a","b","c","d","e"]]</p>
<p>extend :</p>
<pre><code>print list1.extend(list2)
</code></pre>
<p>output : [1,2,3,4,5,"a","b","c","d","e"]</p>
| 2 | 2014-09-18T19:19:57Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 26,397,913 | <p>Append add the entire data at once. The whole data will be added to the newly created index. On the other hand Extend as it name suggests extends the current array.
for example</p>
<pre><code>list1 = [123, 456, 678]
list2 = [111,222]
</code></pre>
<p>when append we get:</p>
<pre><code>result = [123,456,678,[111,... | 3 | 2014-10-16T06:49:07Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 28,119,966 | <blockquote>
<h1>What is the difference between the list methods append and extend?</h1>
</blockquote>
<ul>
<li><code>append</code> adds its argument as a single element to the end of a list. The length of the list itself will increase by one.</li>
<li><code>extend</code> iterates over its argument adding each eleme... | 58 | 2015-01-23T22:44:37Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 32,049,895 | <pre><code>Append a dictionary to another one:
>>>def asd():
dic = {1:'a',2:'b',3:'c',4:'a'}
newdic={5:'v',1:'aa'}
for i in dic.keys():
if not newdic.has_key(dic[i]):
newdic[i] = dic[i]
print "appended one:",newdic
>>>asd()
appended one: {1: 'a', 2: 'b', 3: 'c', 4:... | 3 | 2015-08-17T12:02:46Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 37,787,163 | <p><strong><em>append()</em></strong> : It is basically used in python to add, one element.</p>
<blockquote>
<p>Example 1:</p>
</blockquote>
<pre><code>>>a=[1,2,3,4]
>>a.append(5)
>>print(a)
>>a=[1,2,3,4,5]
</code></pre>
<blockquote>
<p>Example 2:</p>
</blockquote>
<pre><code>>>a=... | 1 | 2016-06-13T10:17:46Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 39,256,096 | <p>The method "append" adds its parameter as a <strong>single element</strong> to the list, while "extend" gets a list and adds its content.</p>
<p>for example, </p>
<blockquote>
<p><strong>extend</strong></p>
</blockquote>
<pre><code> letters = ['a', 'b']
letters.extend(['c', 'd'])
print(letters)... | 0 | 2016-08-31T17:55:10Z | [
"python",
"list",
"append",
"extend"
] |
append vs. extend | 252,703 | <p>What's the difference between the list methods <code>append()</code> and <code>extend()</code>?</p>
| 1,581 | 2008-10-31T05:55:36Z | 39,256,397 | <p>extend(L) extends the list by appending all the items in the given list L.</p>
<pre><code>>>> a
[1, 2, 3]
a.extend([4) #is eqivalent of a[len(a):] = [4]
>>>a
[1, 2, 3, 4]
a =[1,2,3]
>>> a
[1, 2, 3]
>>> a[len(a):] = [4]
>>> a
[1, 2, 3, 4]
</code></pre>
| 0 | 2016-08-31T18:14:42Z | [
"python",
"list",
"append",
"extend"
] |
Finding invocations of a certain function in a c++ file using python | 252,951 | <p>I need to find all occurrences of a function call in a c++ file using python, and extract the arguments for each call.<br />
I'm playing with the <a href="http://www.language-binding.net/pygccxml/pygccxml.html" rel="nofollow">pygccxml</a> package, and extracting the arguments given a string with the function call is... | 1 | 2008-10-31T09:24:45Z | 252,996 | <p>XML-GCC can't do that, because it only reports the data types (and function signatures). It ignores the function bodies. To see that, create a.cc:</p>
<pre><code>void foo()
{}
void bar()
{
foo();
}
</code></pre>
<p>and then run <code>gccxml a.cc -fxml=a.xml</code>. Look at the generated a.xml, to see that... | 2 | 2008-10-31T09:56:52Z | [
"c++",
"python",
"parsing"
] |
How to configure the import path in Visual Studio IronPython projects | 253,018 | <p>I have built the IronPythonIntegration solution that comes with the Visual Studio 2005 SDK (as explained at <a href="http://www.izume.com/2007/10/13/integrating-ironpython-with-visual-studio-2005" rel="nofollow">http://www.izume.com/2007/10/13/integrating-ironpython-with-visual-studio-2005</a>), and I can now use Ir... | 3 | 2008-10-31T10:08:50Z | 253,273 | <p>Set the environment variable IRONPYTHONPATH in your operating system to 'c:\Python24\lib'. (Or anywhere else you need).</p>
| 2 | 2008-10-31T12:06:12Z | [
"python",
"visual-studio",
"ironpython",
"ironpython-studio"
] |
What Python bindings are there for CVS or SVN? | 253,375 | <p>I once did a cursory search and found no good CVS bindings for Python. I wanted to be able to write helper scripts to do some fine-grained manipulation of the repository and projects in it. I had to resort to using <code>popen</code> and checking <code>stdout</code> and <code>stderr</code> and then parsing those. ... | 13 | 2008-10-31T12:51:14Z | 253,390 | <p>For cvs, <a href="http://pycvs.sourceforge.net/" rel="nofollow">pyCVS</a> may be worth a look.</p>
<p>For svn, there is <a href="http://pysvn.tigris.org/" rel="nofollow">pysvn</a>, which is pretty good.</p>
| 8 | 2008-10-31T13:01:31Z | [
"python",
"svn",
"version-control",
"cvs"
] |
What Python bindings are there for CVS or SVN? | 253,375 | <p>I once did a cursory search and found no good CVS bindings for Python. I wanted to be able to write helper scripts to do some fine-grained manipulation of the repository and projects in it. I had to resort to using <code>popen</code> and checking <code>stdout</code> and <code>stderr</code> and then parsing those. ... | 13 | 2008-10-31T12:51:14Z | 254,092 | <p><a href="http://progetti.arstecnica.it/tailor" rel="nofollow">Tailor</a>, a Python program which lets different version control systems interoperate, simply calls the external programs <code>cvs</code> and <code>svn</code> when working with repositories of those formats. This seems pretty ugly, but reduces Tailor's... | 1 | 2008-10-31T16:23:37Z | [
"python",
"svn",
"version-control",
"cvs"
] |
Looking a generic Python script to add a field and populate the field with conditions | 253,761 | <p>I am looking for a script to allow users to add a text field to a .dbf table(e.g. landuse categories) and allow them to input/update the rows basing on what values in the GRIDCODE (numeric categories) field they think should be assigned into text categories.i.e. if GRIDCODE value is 4, the corresponding field value... | 0 | 2008-10-31T14:42:28Z | 253,837 | <p>When you say dbf table, are you referring to ESRI shape file dbf files, which are in fact dbase files? If so you could implement such a thing pretty easily with the python wrapper for <a href="http://shapelib.maptools.org/" rel="nofollow">shapelib,</a> which also supports dbf files.</p>
| 2 | 2008-10-31T15:03:26Z | [
"python",
"sql",
"sql-update"
] |
In Python, is there a concise way of comparing whether the contents of two text files are the same? | 254,350 | <p>I don't care what the differences are. I just want to know whether the contents are different.</p>
| 29 | 2008-10-31T17:47:39Z | 254,357 | <p>The low level way:</p>
<pre><code>from __future__ import with_statement
with open(filename1) as f1:
with open(filename2) as f2:
if f1.read() == f2.read():
...
</code></pre>
<p>The high level way:</p>
<pre><code>import filecmp
if filecmp.cmp(filename1, filename2, shallow=False):
...
</code></p... | 40 | 2008-10-31T17:50:04Z | [
"python"
] |
In Python, is there a concise way of comparing whether the contents of two text files are the same? | 254,350 | <p>I don't care what the differences are. I just want to know whether the contents are different.</p>
| 29 | 2008-10-31T17:47:39Z | 254,362 | <pre>
<code>
f = open(filename1, "r").read()
f2 = open(filename2,"r").read()
print f == f2
</code>
</pre>
| 1 | 2008-10-31T17:52:16Z | [
"python"
] |
In Python, is there a concise way of comparing whether the contents of two text files are the same? | 254,350 | <p>I don't care what the differences are. I just want to know whether the contents are different.</p>
| 29 | 2008-10-31T17:47:39Z | 254,373 | <p>If you're going for even basic efficiency, you probably want to check the file size first:</p>
<pre><code>if os.path.getsize(filename1) == os.path.getsize(filename2):
if open('filename1','r').read() == open('filename2','r').read():
# Files are the same.
</code></pre>
<p>This saves you reading every line of t... | 20 | 2008-10-31T17:56:15Z | [
"python"
] |
In Python, is there a concise way of comparing whether the contents of two text files are the same? | 254,350 | <p>I don't care what the differences are. I just want to know whether the contents are different.</p>
| 29 | 2008-10-31T17:47:39Z | 254,374 | <p>For larger files you could compute a <a href="http://docs.python.org/library/md5.html" rel="nofollow">MD5</a> or <a href="http://docs.python.org/library/sha.html" rel="nofollow">SHA</a> hash of the files.</p>
| 1 | 2008-10-31T17:56:33Z | [
"python"
] |
In Python, is there a concise way of comparing whether the contents of two text files are the same? | 254,350 | <p>I don't care what the differences are. I just want to know whether the contents are different.</p>
| 29 | 2008-10-31T17:47:39Z | 254,518 | <p>I would use a hash of the file's contents using MD5.</p>
<pre><code>import hashlib
def checksum(f):
md5 = hashlib.md5()
md5.update(open(f).read())
return md5.hexdigest()
def is_contents_same(f1, f2):
return checksum(f1) == checksum(f2)
if not is_contents_same('foo.txt', 'bar.txt'):
print 'The... | 1 | 2008-10-31T18:53:52Z | [
"python"
] |
In Python, is there a concise way of comparing whether the contents of two text files are the same? | 254,350 | <p>I don't care what the differences are. I just want to know whether the contents are different.</p>
| 29 | 2008-10-31T17:47:39Z | 254,567 | <p>Since I can't comment on the answers of others I'll write my own.</p>
<p>If you use md5 you definitely must not just md5.update(f.read()) since you'll use too much memory.</p>
<pre><code>def get_file_md5(f, chunk_size=8192):
h = hashlib.md5()
while True:
chunk = f.read(chunk_size)
if not ch... | 5 | 2008-10-31T19:06:03Z | [
"python"
] |
In Python, is there a concise way of comparing whether the contents of two text files are the same? | 254,350 | <p>I don't care what the differences are. I just want to know whether the contents are different.</p>
| 29 | 2008-10-31T17:47:39Z | 255,210 | <p>This is a functional-style file comparison function. It returns instantly False if the files have different sizes; otherwise, it reads in 4KiB block sizes and returns False instantly upon the first difference:</p>
<pre><code>from __future__ import with_statement
import os
import itertools, functools, operator
def ... | 5 | 2008-10-31T23:03:01Z | [
"python"
] |
Tiny python executable? | 254,635 | <p>I plan to use PyInstaller to create a stand-alone python executable. PythonInstaller comes with built-in support for UPX and uses it to compress the executable but they are still really huge (about 2,7 mb).</p>
<p>Is there any way to create even smaller Python executables? For example using a shrinked python.dll or... | 8 | 2008-10-31T19:20:30Z | 254,723 | <p>If you recompile pythonxy.dll, you can omit modules that you don't need. Going by size, stripping off the unicode database and the CJK codes creates the largest code reduction. This, of course, assumes that you don't need these. Remove the modules from the pythoncore project, and also remove them from PC/config.c</... | 9 | 2008-10-31T19:51:46Z | [
"python",
"executable",
"pyinstaller"
] |
Tiny python executable? | 254,635 | <p>I plan to use PyInstaller to create a stand-alone python executable. PythonInstaller comes with built-in support for UPX and uses it to compress the executable but they are still really huge (about 2,7 mb).</p>
<p>Is there any way to create even smaller Python executables? For example using a shrinked python.dll or... | 8 | 2008-10-31T19:20:30Z | 255,582 | <p>You can't go too low in size, because you obviously need to bundle the Python interpreter in, and only that takes a considerable amount of space.</p>
<p>I had the same concerns once, and there are two approaches:</p>
<ol>
<li>Install Python on the computers you want to run on and only distribute the scripts</li>
<... | 1 | 2008-11-01T06:32:59Z | [
"python",
"executable",
"pyinstaller"
] |
Tiny python executable? | 254,635 | <p>I plan to use PyInstaller to create a stand-alone python executable. PythonInstaller comes with built-in support for UPX and uses it to compress the executable but they are still really huge (about 2,7 mb).</p>
<p>Is there any way to create even smaller Python executables? For example using a shrinked python.dll or... | 8 | 2008-10-31T19:20:30Z | 4,902,830 | <p>Using a earlier Python version will also decrease the size considerably if your really needing a small file size. I don't recommend using a very old version, Python2.3 would be the best option. I got my Python executable size to 700KB's! Also I prefer Py2Exe over Pyinstaller.</p>
| 1 | 2011-02-04T20:54:15Z | [
"python",
"executable",
"pyinstaller"
] |
How to embed a tag within a url templatetag in a django template? | 254,895 | <p>How do I embed a tag within a <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#url" rel="nofollow" title="url templatetag">url templatetag</a> in a django template?</p>
<p>Django 1.0 , Python 2.5.2</p>
<p>In views.py</p>
<pre><code>def home_page_view(request):
NUP={"HOMEPAGE": "named-url-... | 2 | 2008-10-31T20:45:04Z | 254,942 | <p>That's seems way too dynamic. You're supposed to do</p>
<pre><code>{% url named-url-pattern-string-for-my-home-page-view %}
</code></pre>
<p>And leave it at that. Dynamically filling in the name of the URL tag is -- frankly -- a little odd. </p>
<p>If you want to use any of a large number of different URL tags... | 0 | 2008-10-31T20:59:47Z | [
"python",
"django",
"url",
"templates",
"templatetag"
] |
How to embed a tag within a url templatetag in a django template? | 254,895 | <p>How do I embed a tag within a <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#url" rel="nofollow" title="url templatetag">url templatetag</a> in a django template?</p>
<p>Django 1.0 , Python 2.5.2</p>
<p>In views.py</p>
<pre><code>def home_page_view(request):
NUP={"HOMEPAGE": "named-url-... | 2 | 2008-10-31T20:45:04Z | 254,948 | <p>Maybe you could try passing the final URL to the template, instead?</p>
<p>Something like this:</p>
<pre><code>from django.core.urlresolvers import reverse
def home_page_view(request):
NUP={"HOMEPAGE": reverse('named-url-pattern-string-for-my-home-page-view')}
variables = RequestContext(request, {'NUP... | 2 | 2008-10-31T21:00:30Z | [
"python",
"django",
"url",
"templates",
"templatetag"
] |
How to embed a tag within a url templatetag in a django template? | 254,895 | <p>How do I embed a tag within a <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#url" rel="nofollow" title="url templatetag">url templatetag</a> in a django template?</p>
<p>Django 1.0 , Python 2.5.2</p>
<p>In views.py</p>
<pre><code>def home_page_view(request):
NUP={"HOMEPAGE": "named-url-... | 2 | 2008-10-31T20:45:04Z | 751,683 | <p>Posted a bug to Django. They should be able to fix this on their side.</p>
<p><a href="http://code.djangoproject.com/ticket/10823" rel="nofollow">http://code.djangoproject.com/ticket/10823</a></p>
| 0 | 2009-04-15T13:28:15Z | [
"python",
"django",
"url",
"templates",
"templatetag"
] |
Converting datetime to POSIX time | 255,035 | <p>How do I convert a datetime or date object into a POSIX timestamp in python? There are methods to create a datetime object out of a timestamp, but I don't seem to find any obvious ways to do the operation the opposite way.</p>
| 36 | 2008-10-31T21:38:02Z | 255,053 | <pre><code>import time, datetime
d = datetime.datetime.now()
print time.mktime(d.timetuple())
</code></pre>
| 44 | 2008-10-31T21:44:35Z | [
"python",
"datetime",
"posix"
] |
Converting datetime to POSIX time | 255,035 | <p>How do I convert a datetime or date object into a POSIX timestamp in python? There are methods to create a datetime object out of a timestamp, but I don't seem to find any obvious ways to do the operation the opposite way.</p>
| 36 | 2008-10-31T21:38:02Z | 5,872,022 | <p>For UTC calculations, <code>calendar.timegm</code> is the inverse of <code>time.gmtime</code>.</p>
<pre><code>import calendar, datetime
d = datetime.datetime.utcnow()
print calendar.timegm(d.timetuple())
</code></pre>
| 19 | 2011-05-03T15:39:15Z | [
"python",
"datetime",
"posix"
] |
Converting datetime to POSIX time | 255,035 | <p>How do I convert a datetime or date object into a POSIX timestamp in python? There are methods to create a datetime object out of a timestamp, but I don't seem to find any obvious ways to do the operation the opposite way.</p>
| 36 | 2008-10-31T21:38:02Z | 14,369,386 | <p>In python, time.time() can return seconds as a floating point number that includes a decimal component with the microseconds. In order to convert a datetime back to this representation, you have to add the microseconds component because the direct timetuple doesn't include it.</p>
<pre><code>import time, datetime
... | 3 | 2013-01-16T22:52:43Z | [
"python",
"datetime",
"posix"
] |
How do I keep Python print from adding newlines or spaces? | 255,147 | <p>In python, if I say</p>
<pre><code>print 'h'
</code></pre>
<p>I get the letter h and a newline. If I say </p>
<pre><code>print 'h',
</code></pre>
<p>I get the letter h and no newline. If I say</p>
<pre><code>print 'h',
print 'm',
</code></pre>
<p>I get the letter h, a space, and the letter m. How can I prev... | 169 | 2008-10-31T22:33:21Z | 255,154 | <p>You can use:</p>
<pre><code>sys.stdout.write('h')
sys.stdout.write('m')
</code></pre>
| 147 | 2008-10-31T22:35:49Z | [
"python",
"printing",
"formatting",
"python-2.x"
] |
How do I keep Python print from adding newlines or spaces? | 255,147 | <p>In python, if I say</p>
<pre><code>print 'h'
</code></pre>
<p>I get the letter h and a newline. If I say </p>
<pre><code>print 'h',
</code></pre>
<p>I get the letter h and no newline. If I say</p>
<pre><code>print 'h',
print 'm',
</code></pre>
<p>I get the letter h, a space, and the letter m. How can I prev... | 169 | 2008-10-31T22:33:21Z | 255,172 | <p>Just a comment. In <a href="http://docs.python.org/dev/3.0/whatsnew/3.0.html">Python 3</a>, you will use</p>
<pre><code>print('h', end='')
</code></pre>
<p>to suppress the endline terminator, and</p>
<pre><code>print('a', 'b', 'c', sep='')
</code></pre>
<p>to suppress the whitespace separator between items.</p>
| 186 | 2008-10-31T22:44:14Z | [
"python",
"printing",
"formatting",
"python-2.x"
] |
How do I keep Python print from adding newlines or spaces? | 255,147 | <p>In python, if I say</p>
<pre><code>print 'h'
</code></pre>
<p>I get the letter h and a newline. If I say </p>
<pre><code>print 'h',
</code></pre>
<p>I get the letter h and no newline. If I say</p>
<pre><code>print 'h',
print 'm',
</code></pre>
<p>I get the letter h, a space, and the letter m. How can I prev... | 169 | 2008-10-31T22:33:21Z | 255,199 | <p>Greg is right-- you can use sys.stdout.write</p>
<p>Perhaps, though, you should consider refactoring your algorithm to accumulate a list of <whatevers> and then</p>
<pre><code>lst = ['h', 'm']
print "".join(lst)
</code></pre>
| 33 | 2008-10-31T22:53:52Z | [
"python",
"printing",
"formatting",
"python-2.x"
] |
How do I keep Python print from adding newlines or spaces? | 255,147 | <p>In python, if I say</p>
<pre><code>print 'h'
</code></pre>
<p>I get the letter h and a newline. If I say </p>
<pre><code>print 'h',
</code></pre>
<p>I get the letter h and no newline. If I say</p>
<pre><code>print 'h',
print 'm',
</code></pre>
<p>I get the letter h, a space, and the letter m. How can I prev... | 169 | 2008-10-31T22:33:21Z | 255,306 | <pre><code>Python 2.5.2 (r252:60911, Sep 27 2008, 07:03:14)
[GCC 4.3.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print "hello",; print "there"
hello there
>>> print "hello",; sys.stdout.softspace=False; print "there"
hellothere
</code... | 18 | 2008-11-01T00:21:28Z | [
"python",
"printing",
"formatting",
"python-2.x"
] |
How do I keep Python print from adding newlines or spaces? | 255,147 | <p>In python, if I say</p>
<pre><code>print 'h'
</code></pre>
<p>I get the letter h and a newline. If I say </p>
<pre><code>print 'h',
</code></pre>
<p>I get the letter h and no newline. If I say</p>
<pre><code>print 'h',
print 'm',
</code></pre>
<p>I get the letter h, a space, and the letter m. How can I prev... | 169 | 2008-10-31T22:33:21Z | 255,336 | <p>For completeness, one other way is to clear the softspace value after performing the write.</p>
<pre><code>import sys
print "hello",
sys.stdout.softspace=0
print "world",
print "!"
</code></pre>
<p>prints <code>helloworld !</code></p>
<p>Using stdout.write() is probably more convenient for most cases though.</p>
| 13 | 2008-11-01T00:43:51Z | [
"python",
"printing",
"formatting",
"python-2.x"
] |
How do I keep Python print from adding newlines or spaces? | 255,147 | <p>In python, if I say</p>
<pre><code>print 'h'
</code></pre>
<p>I get the letter h and a newline. If I say </p>
<pre><code>print 'h',
</code></pre>
<p>I get the letter h and no newline. If I say</p>
<pre><code>print 'h',
print 'm',
</code></pre>
<p>I get the letter h, a space, and the letter m. How can I prev... | 169 | 2008-10-31T22:33:21Z | 410,850 | <p>Or use a <code>+</code>, i.e.:</p>
<pre><code>>>> print 'me'+'no'+'likee'+'spacees'+'pls'
menolikeespaceespls
</code></pre>
<p>Just make sure all are concatenate-able objects.</p>
| 15 | 2009-01-04T11:27:42Z | [
"python",
"printing",
"formatting",
"python-2.x"
] |
How do I keep Python print from adding newlines or spaces? | 255,147 | <p>In python, if I say</p>
<pre><code>print 'h'
</code></pre>
<p>I get the letter h and a newline. If I say </p>
<pre><code>print 'h',
</code></pre>
<p>I get the letter h and no newline. If I say</p>
<pre><code>print 'h',
print 'm',
</code></pre>
<p>I get the letter h, a space, and the letter m. How can I prev... | 169 | 2008-10-31T22:33:21Z | 1,036,396 | <p>Regain control of your console! Simply:</p>
<pre><code>from __past__ import printf
</code></pre>
<p>where <code>__past__.py</code> contains:</p>
<pre><code>import sys
def printf(fmt, *varargs):
sys.stdout.write(fmt % varargs)
</code></pre>
<p>then:</p>
<pre><code>>>> printf("Hello, world!\n")
Hello... | 8 | 2009-06-24T04:26:03Z | [
"python",
"printing",
"formatting",
"python-2.x"
] |
How do I keep Python print from adding newlines or spaces? | 255,147 | <p>In python, if I say</p>
<pre><code>print 'h'
</code></pre>
<p>I get the letter h and a newline. If I say </p>
<pre><code>print 'h',
</code></pre>
<p>I get the letter h and no newline. If I say</p>
<pre><code>print 'h',
print 'm',
</code></pre>
<p>I get the letter h, a space, and the letter m. How can I prev... | 169 | 2008-10-31T22:33:21Z | 20,677,875 | <p>This may look stupid, but seems to be the simplest:</p>
<pre><code> print 'h',
print '\bm'
</code></pre>
| 11 | 2013-12-19T09:32:40Z | [
"python",
"printing",
"formatting",
"python-2.x"
] |
How do I keep Python print from adding newlines or spaces? | 255,147 | <p>In python, if I say</p>
<pre><code>print 'h'
</code></pre>
<p>I get the letter h and a newline. If I say </p>
<pre><code>print 'h',
</code></pre>
<p>I get the letter h and no newline. If I say</p>
<pre><code>print 'h',
print 'm',
</code></pre>
<p>I get the letter h, a space, and the letter m. How can I prev... | 169 | 2008-10-31T22:33:21Z | 21,369,899 | <p>You can use print like the printf function in C.</p>
<p>e.g.</p>
<p>print "%s%s" % (x, y)</p>
| 0 | 2014-01-26T22:06:39Z | [
"python",
"printing",
"formatting",
"python-2.x"
] |
How do I keep Python print from adding newlines or spaces? | 255,147 | <p>In python, if I say</p>
<pre><code>print 'h'
</code></pre>
<p>I get the letter h and a newline. If I say </p>
<pre><code>print 'h',
</code></pre>
<p>I get the letter h and no newline. If I say</p>
<pre><code>print 'h',
print 'm',
</code></pre>
<p>I get the letter h, a space, and the letter m. How can I prev... | 169 | 2008-10-31T22:33:21Z | 23,247,362 | <p>In python 2.6:</p>
<pre><code>>>> print 'h','m','h'
h m h
>>> from __future__ import print_function
>>> print('h',end='')
h>>> print('h',end='');print('m',end='');print('h',end='')
hmh>>>
>>> print('h','m','h',sep='');
hmh
>>>
</code></pre>
<p>So using... | 2 | 2014-04-23T14:27:07Z | [
"python",
"printing",
"formatting",
"python-2.x"
] |
How do I keep Python print from adding newlines or spaces? | 255,147 | <p>In python, if I say</p>
<pre><code>print 'h'
</code></pre>
<p>I get the letter h and a newline. If I say </p>
<pre><code>print 'h',
</code></pre>
<p>I get the letter h and no newline. If I say</p>
<pre><code>print 'h',
print 'm',
</code></pre>
<p>I get the letter h, a space, and the letter m. How can I prev... | 169 | 2008-10-31T22:33:21Z | 24,686,404 | <pre><code>print("{0}{1}{2}".format(a, b, c))
</code></pre>
| -1 | 2014-07-10T21:13:39Z | [
"python",
"printing",
"formatting",
"python-2.x"
] |
How do I keep Python print from adding newlines or spaces? | 255,147 | <p>In python, if I say</p>
<pre><code>print 'h'
</code></pre>
<p>I get the letter h and a newline. If I say </p>
<pre><code>print 'h',
</code></pre>
<p>I get the letter h and no newline. If I say</p>
<pre><code>print 'h',
print 'm',
</code></pre>
<p>I get the letter h, a space, and the letter m. How can I prev... | 169 | 2008-10-31T22:33:21Z | 26,343,928 | <p>I am not adding a new answer. I am just putting the best marked answer in a better format.
I can see that the best answer by rating is using <code>sys.stdout.write(someString)</code>. You can try this out:</p>
<pre><code> import sys
Print = sys.stdout.write
Print("Hello")
Print("World")
</code></pre>... | 5 | 2014-10-13T15:46:56Z | [
"python",
"printing",
"formatting",
"python-2.x"
] |
How do I keep Python print from adding newlines or spaces? | 255,147 | <p>In python, if I say</p>
<pre><code>print 'h'
</code></pre>
<p>I get the letter h and a newline. If I say </p>
<pre><code>print 'h',
</code></pre>
<p>I get the letter h and no newline. If I say</p>
<pre><code>print 'h',
print 'm',
</code></pre>
<p>I get the letter h, a space, and the letter m. How can I prev... | 169 | 2008-10-31T22:33:21Z | 27,295,541 | <p><code>sys.stdout.write</code> is (in Python 2) the only robust solution. Python 2 printing is insane. Consider this code:</p>
<pre><code>print "a",
print "b",
</code></pre>
<p>This will print <code>a b</code>, leading you to suspect that it is printing a trailing space. But this is not correct. Try this instead:</... | 0 | 2014-12-04T13:41:52Z | [
"python",
"printing",
"formatting",
"python-2.x"
] |
How do I keep Python print from adding newlines or spaces? | 255,147 | <p>In python, if I say</p>
<pre><code>print 'h'
</code></pre>
<p>I get the letter h and a newline. If I say </p>
<pre><code>print 'h',
</code></pre>
<p>I get the letter h and no newline. If I say</p>
<pre><code>print 'h',
print 'm',
</code></pre>
<p>I get the letter h, a space, and the letter m. How can I prev... | 169 | 2008-10-31T22:33:21Z | 29,714,273 | <pre><code>import sys
a=raw_input()
for i in range(0,len(a)):
sys.stdout.write(a[i])
</code></pre>
| -1 | 2015-04-18T07:21:47Z | [
"python",
"printing",
"formatting",
"python-2.x"
] |
How to override HTTP request verb in GAE | 255,157 | <p>In the context of a Google App Engine Webapp framework application:</p>
<p>I want to changed the request verb of a request in the case a
parameter _method is provided, for example if a POST request comes in
with a parameter _method=PUT, I need to change the request to call the
put method of the handler. This is to ... | 1 | 2008-10-31T22:37:00Z | 255,906 | <p>Calling the handler from initialize isn't the right way anyway - if you do that, the webapp will then call the original handler as well.</p>
<p>Instead, you have a couple of options:</p>
<ul>
<li>You can subclass webapp.WSGIApplication and override <strong>call</strong> to select the method based on _method when i... | 3 | 2008-11-01T18:22:13Z | [
"python",
"google-app-engine",
"rest",
"metaclass"
] |
How to override HTTP request verb in GAE | 255,157 | <p>In the context of a Google App Engine Webapp framework application:</p>
<p>I want to changed the request verb of a request in the case a
parameter _method is provided, for example if a POST request comes in
with a parameter _method=PUT, I need to change the request to call the
put method of the handler. This is to ... | 1 | 2008-10-31T22:37:00Z | 257,094 | <p>Thats Arachnid for your response. Pointing me to the source of the framework was really helpful. Last I looked the source wasn't there(there was only .pyc), maybe it changed with the new version of the SDK. For my situation I think overriding WSGIApplication would have been the right thing to do. However, I chose to... | 2 | 2008-11-02T17:35:47Z | [
"python",
"google-app-engine",
"rest",
"metaclass"
] |
Storage transactions in Redland's Python bindings? | 255,263 | <p>I've currently skimming through the Python-bindings for Redland and haven't found a clean way to do transactions on the storage engine via it. I found some model-transactions within the low-level Redland module:</p>
<pre><code>import RDF, Redland
storage = RDF.Storage(...)
model = RDF.Model(storage)
Redland.librdf... | 4 | 2008-10-31T23:42:20Z | 257,582 | <p>Yes, this should work. There are no convenience functions for the model class in the python wrapper right now but they would be similar to what you wrote:</p>
<pre><code>class Model(object):
...
def transaction_start(self):
return Redland.librdf_model_transaction_start(self._model)
</code></pre>
| 3 | 2008-11-02T23:40:46Z | [
"python",
"transactions",
"rdf",
"rdfstore",
"redland"
] |
Python re.findall with groupdicts | 255,332 | <p>I kind of wish that there were a version of <code>re.findall</code> that returned <code>groupdict</code>s instead of just <code>group</code>s. Am I missing some simple way to accomplish the same result? (Does anybody know of a reason that this function doesn't exist?)</p>
| 8 | 2008-11-01T00:41:54Z | 255,344 | <p>You could use the finditer() function. This will give you a sequence of match objects, so you can get the groupdict for each with:</p>
<pre><code>[m.groupdict() for m in regex.finditer(search_string)]
</code></pre>
| 19 | 2008-11-01T00:52:19Z | [
"python",
"regex"
] |
Determine if a named parameter was passed | 255,429 | <p>I would like to know if it is possible to determine if a function parameter with a default value was passed in Python.
For example, how does dict.pop work?</p>
<pre><code>>>> {}.pop('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'pop(): dictionary is ... | 10 | 2008-11-01T02:23:27Z | 255,433 | <p>You can do it like this:</p>
<pre><code>def isdefarg(*args):
if len(args) > 0:
print len(args), "arguments"
else:
print "no arguments"
isdefarg()
isdefarg(None)
isdefarg(5, 7)
</code></pre>
<p>See the Python documentation on <a href="http://python.org/doc/2.5/ref/calls.html" rel="nofoll... | 1 | 2008-11-01T02:34:46Z | [
"python",
"default-value",
"named-parameters"
] |
Determine if a named parameter was passed | 255,429 | <p>I would like to know if it is possible to determine if a function parameter with a default value was passed in Python.
For example, how does dict.pop work?</p>
<pre><code>>>> {}.pop('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'pop(): dictionary is ... | 10 | 2008-11-01T02:23:27Z | 255,438 | <p>I guess you mean "keyword argument", when you say "named parameter". <code>dict.pop()</code> does not accept keyword argument, so this part of the question is moot.</p>
<pre><code>>>> {}.pop('test', d=None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: pop(... | 6 | 2008-11-01T02:45:13Z | [
"python",
"default-value",
"named-parameters"
] |
Determine if a named parameter was passed | 255,429 | <p>I would like to know if it is possible to determine if a function parameter with a default value was passed in Python.
For example, how does dict.pop work?</p>
<pre><code>>>> {}.pop('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'pop(): dictionary is ... | 10 | 2008-11-01T02:23:27Z | 255,446 | <pre><code>def f(one, two=2):
print "I wonder if", two, "has been passed or not..."
f(1, 2)
</code></pre>
<p>If this is the exact meaning of your question, I think that there is no way to distinguish between a 2 that was in the default value and a 2 that has been passed. I didn't find how to accomplish such distin... | 1 | 2008-11-01T02:58:41Z | [
"python",
"default-value",
"named-parameters"
] |
Determine if a named parameter was passed | 255,429 | <p>I would like to know if it is possible to determine if a function parameter with a default value was passed in Python.
For example, how does dict.pop work?</p>
<pre><code>>>> {}.pop('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'pop(): dictionary is ... | 10 | 2008-11-01T02:23:27Z | 255,472 | <p>I am not certain if I fully understand what is it you want; however:</p>
<pre><code>def fun(arg=Ellipsis):
if arg is Ellipsis:
print "No arg provided"
else:
print "arg provided:", repr(arg)
</code></pre>
<p>does that do what you want? If not, then as others have suggested, you should declar... | 1 | 2008-11-01T03:19:07Z | [
"python",
"default-value",
"named-parameters"
] |
Determine if a named parameter was passed | 255,429 | <p>I would like to know if it is possible to determine if a function parameter with a default value was passed in Python.
For example, how does dict.pop work?</p>
<pre><code>>>> {}.pop('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'pop(): dictionary is ... | 10 | 2008-11-01T02:23:27Z | 255,580 | <p>The convention is often to use <code>arg=None</code> and use</p>
<pre><code>def foo(arg=None):
if arg is None:
arg = "default value"
# other stuff
# ...
</code></pre>
<p>to check if it was passed or not. Allowing the user to pass <code>None</code>, which would be interpreted as if the argum... | 7 | 2008-11-01T06:17:54Z | [
"python",
"default-value",
"named-parameters"
] |
Browser-based application or stand-alone GUI app? | 255,476 | <p>I'm sure this has been asked before, but I can't find it. </p>
<p>What are the benefits/limitations of using a browser-based interface for a stand-alone application vs. using a normal GUI framework?</p>
<p>I'm working on a Python program currently implement with wxPython for the GUI. The application is simply user... | 22 | 2008-11-01T03:25:09Z | 255,481 | <p>The obvious advantages to browser-based:</p>
<ul>
<li>you can present the same UI regardless of platform</li>
<li>you can upgrade the application easily, and all users have the same version of the app running</li>
<li>you know the environment that your application will be running in (the server hardware/OS) which m... | 10 | 2008-11-01T03:29:53Z | [
"python",
"user-interface",
"browser"
] |
Browser-based application or stand-alone GUI app? | 255,476 | <p>I'm sure this has been asked before, but I can't find it. </p>
<p>What are the benefits/limitations of using a browser-based interface for a stand-alone application vs. using a normal GUI framework?</p>
<p>I'm working on a Python program currently implement with wxPython for the GUI. The application is simply user... | 22 | 2008-11-01T03:25:09Z | 255,484 | <p>Browsers can be accessed anywhere with internet and you deploy it on the server. The desktop app has to be deployed to their computers and each computer somehow has its own uniqueness even with same OS and same version. This could bring you lots of hassles.
Go for web.</p>
| 0 | 2008-11-01T03:30:08Z | [
"python",
"user-interface",
"browser"
] |
Browser-based application or stand-alone GUI app? | 255,476 | <p>I'm sure this has been asked before, but I can't find it. </p>
<p>What are the benefits/limitations of using a browser-based interface for a stand-alone application vs. using a normal GUI framework?</p>
<p>I'm working on a Python program currently implement with wxPython for the GUI. The application is simply user... | 22 | 2008-11-01T03:25:09Z | 255,491 | <p>When it comes to simple data entry using user-entry forms, I'd argue that using a browser-based solution would probably be easier and faster to develop.</p>
<p>Unless your core feature is the interface itself ("<em>If it's a core business function -- do it yourself, no matter what.</em>" , see <a href="http://www.j... | 4 | 2008-11-01T03:37:23Z | [
"python",
"user-interface",
"browser"
] |
Browser-based application or stand-alone GUI app? | 255,476 | <p>I'm sure this has been asked before, but I can't find it. </p>
<p>What are the benefits/limitations of using a browser-based interface for a stand-alone application vs. using a normal GUI framework?</p>
<p>I'm working on a Python program currently implement with wxPython for the GUI. The application is simply user... | 22 | 2008-11-01T03:25:09Z | 255,501 | <p>Benefits of browser-based interface:</p>
<ul>
<li>Easier to manage: no installation required on user machines, upgrades need only be performed on server side and are immediately available to all users. Data backup can be performed on a single machine as data won't be spread out across multiple clients.</li>
<li>Ap... | 3 | 2008-11-01T03:49:50Z | [
"python",
"user-interface",
"browser"
] |
Browser-based application or stand-alone GUI app? | 255,476 | <p>I'm sure this has been asked before, but I can't find it. </p>
<p>What are the benefits/limitations of using a browser-based interface for a stand-alone application vs. using a normal GUI framework?</p>
<p>I'm working on a Python program currently implement with wxPython for the GUI. The application is simply user... | 22 | 2008-11-01T03:25:09Z | 255,505 | <p>There's pretty good evidence that the trump-card issue in most cases is deployability and supportability. Browser apps are lower overhead in general; implementing and supporting more than a couple dozen users can end up consuming substantial support resources.</p>
<p>I saw a table a year or two ago that showed some... | 2 | 2008-11-01T03:51:15Z | [
"python",
"user-interface",
"browser"
] |
Browser-based application or stand-alone GUI app? | 255,476 | <p>I'm sure this has been asked before, but I can't find it. </p>
<p>What are the benefits/limitations of using a browser-based interface for a stand-alone application vs. using a normal GUI framework?</p>
<p>I'm working on a Python program currently implement with wxPython for the GUI. The application is simply user... | 22 | 2008-11-01T03:25:09Z | 255,508 | <p>Let's pretend for a moment that the development/deployment/maintenance effort/cost is equal and we look at it from the application user's perspective:</p>
<p><em>Which UI is the user going to find more useful?</em></p>
<p>in terms of</p>
<ul>
<li>Ease of use</li>
<li>Responsiveness</li>
<li>Familiar navigation/us... | 10 | 2008-11-01T03:53:47Z | [
"python",
"user-interface",
"browser"
] |
Browser-based application or stand-alone GUI app? | 255,476 | <p>I'm sure this has been asked before, but I can't find it. </p>
<p>What are the benefits/limitations of using a browser-based interface for a stand-alone application vs. using a normal GUI framework?</p>
<p>I'm working on a Python program currently implement with wxPython for the GUI. The application is simply user... | 22 | 2008-11-01T03:25:09Z | 255,514 | <p>For this task (form-based text entry) a browser is great. You don't need anything that being a desktop app will give you (speed, flexibility)</p>
<p>There are draw-backs to being a web-application, such as..</p>
<p><strong>It's a web-page. There are things you just cannot (easily) do</strong></p>
<p>You cannot ea... | 2 | 2008-11-01T04:05:43Z | [
"python",
"user-interface",
"browser"
] |
Browser-based application or stand-alone GUI app? | 255,476 | <p>I'm sure this has been asked before, but I can't find it. </p>
<p>What are the benefits/limitations of using a browser-based interface for a stand-alone application vs. using a normal GUI framework?</p>
<p>I'm working on a Python program currently implement with wxPython for the GUI. The application is simply user... | 22 | 2008-11-01T03:25:09Z | 256,770 | <p>Everything has advantages and disavantages, but:</p>
<p><em>I have yet to use a single browser-based application on localhost, intranet, or internet that feels nice to use, is responsive, and who's user interface isn't strictly limited by the limitations of HTML/JS/CSS.</em></p>
<p>Note: Flash/Java-based UI is an ... | 0 | 2008-11-02T11:07:25Z | [
"python",
"user-interface",
"browser"
] |
Browser-based application or stand-alone GUI app? | 255,476 | <p>I'm sure this has been asked before, but I can't find it. </p>
<p>What are the benefits/limitations of using a browser-based interface for a stand-alone application vs. using a normal GUI framework?</p>
<p>I'm working on a Python program currently implement with wxPython for the GUI. The application is simply user... | 22 | 2008-11-01T03:25:09Z | 266,145 | <p>One of the things I hate about web based UIs is the fact that they run inside another window. Meaning, you have controls -- maybe dozens of them -- that have nothing to do with your application. From a usability point of view this can be confusing though most of us have adapted by "tuning out" the extra stuff. </p>
... | 1 | 2008-11-05T18:29:28Z | [
"python",
"user-interface",
"browser"
] |
Browser-based application or stand-alone GUI app? | 255,476 | <p>I'm sure this has been asked before, but I can't find it. </p>
<p>What are the benefits/limitations of using a browser-based interface for a stand-alone application vs. using a normal GUI framework?</p>
<p>I'm working on a Python program currently implement with wxPython for the GUI. The application is simply user... | 22 | 2008-11-01T03:25:09Z | 574,535 | <p>I think the browser based UI concept is here to stay. There is nothing more portalble than the web itself, and as long as one stays within the boundaries of decent javascript libraries...the rendering would be almost the same. Plus since the rendering is not your headache, you can concern yourself more with develop... | 0 | 2009-02-22T07:41:51Z | [
"python",
"user-interface",
"browser"
] |
Browser-based application or stand-alone GUI app? | 255,476 | <p>I'm sure this has been asked before, but I can't find it. </p>
<p>What are the benefits/limitations of using a browser-based interface for a stand-alone application vs. using a normal GUI framework?</p>
<p>I'm working on a Python program currently implement with wxPython for the GUI. The application is simply user... | 22 | 2008-11-01T03:25:09Z | 2,707,352 | <p>The rich client GUI will generally be faster and better integrated with the look and feel the user is accustomed to deal with - this does not only mean bells and whistles, but also means a lot of time saving features like keyboard shortcuts.</p>
<p>The web based UI will be more portable since does not bound the dev... | 0 | 2010-04-25T06:14:31Z | [
"python",
"user-interface",
"browser"
] |
Browser-based application or stand-alone GUI app? | 255,476 | <p>I'm sure this has been asked before, but I can't find it. </p>
<p>What are the benefits/limitations of using a browser-based interface for a stand-alone application vs. using a normal GUI framework?</p>
<p>I'm working on a Python program currently implement with wxPython for the GUI. The application is simply user... | 22 | 2008-11-01T03:25:09Z | 17,340,205 | <p>My solution is this</p>
<ol>
<li>Website applications obviously go on browsers</li>
<li>Networked applications that do not need accessing client's computer goes by browser</li>
<li>Any application that need to be accessed by more than a client at a time goes by browser</li>
<li>Applications that will be used per cl... | 0 | 2013-06-27T10:00:29Z | [
"python",
"user-interface",
"browser"
] |
How to implement Google Suggest in your own web application (e.g. using Python) | 255,700 | <p>In my website, users have the possibility to store links.</p>
<p>During typing the internet address into the designated field I would like to display a suggest/autocomplete box similar to Google Suggest or the Chrome Omnibar.</p>
<p>Example:</p>
<p>User is typing as URL:</p>
<pre><code>http://www.sta
</code></pr... | 9 | 2008-11-01T15:50:30Z | 255,705 | <p>You could try with
<a href="http://google.com/complete/search?output=toolbar&q=keyword">http://google.com/complete/search?output=toolbar&q=keyword</a></p>
<p>and then parse the xml result.</p>
| 7 | 2008-11-01T15:58:31Z | [
"python",
"autocomplete",
"autosuggest"
] |
How to implement Google Suggest in your own web application (e.g. using Python) | 255,700 | <p>In my website, users have the possibility to store links.</p>
<p>During typing the internet address into the designated field I would like to display a suggest/autocomplete box similar to Google Suggest or the Chrome Omnibar.</p>
<p>Example:</p>
<p>User is typing as URL:</p>
<pre><code>http://www.sta
</code></pr... | 9 | 2008-11-01T15:50:30Z | 255,962 | <p>If you want the auto-complete to use date from your own database, you'll need to do the search yourself and update the suggestions using AJAX as users type. For the search part, you might want to look at <a href="http://lucene.apache.org/java/docs/" rel="nofollow">Lucene</a>.</p>
| 0 | 2008-11-01T19:00:16Z | [
"python",
"autocomplete",
"autosuggest"
] |
How to implement Google Suggest in your own web application (e.g. using Python) | 255,700 | <p>In my website, users have the possibility to store links.</p>
<p>During typing the internet address into the designated field I would like to display a suggest/autocomplete box similar to Google Suggest or the Chrome Omnibar.</p>
<p>Example:</p>
<p>User is typing as URL:</p>
<pre><code>http://www.sta
</code></pr... | 9 | 2008-11-01T15:50:30Z | 256,099 | <p>I did this once before in a Django server. There's two parts - client-side and server-side.</p>
<p>Client side you will have to send out XmlHttpRequests to the server as the user is typing, and then when the information comes back, display it. This part will require a decent amount of javascript, including some tri... | 2 | 2008-11-01T20:59:34Z | [
"python",
"autocomplete",
"autosuggest"
] |
How to implement Google Suggest in your own web application (e.g. using Python) | 255,700 | <p>In my website, users have the possibility to store links.</p>
<p>During typing the internet address into the designated field I would like to display a suggest/autocomplete box similar to Google Suggest or the Chrome Omnibar.</p>
<p>Example:</p>
<p>User is typing as URL:</p>
<pre><code>http://www.sta
</code></pr... | 9 | 2008-11-01T15:50:30Z | 656,122 | <p>Yahoo has a good <a href="http://developer.yahoo.com/yui/autocomplete/" rel="nofollow">autocomplete control</a>.</p>
<p>They have a <a href="http://developer.yahoo.com/yui/examples/autocomplete/ac%5Fbasic%5Farray.html" rel="nofollow">sample here.</a>.</p>
<p>Obviously this does nothing to help you out in getting t... | 1 | 2009-03-17T21:34:59Z | [
"python",
"autocomplete",
"autosuggest"
] |
How to implement Google Suggest in your own web application (e.g. using Python) | 255,700 | <p>In my website, users have the possibility to store links.</p>
<p>During typing the internet address into the designated field I would like to display a suggest/autocomplete box similar to Google Suggest or the Chrome Omnibar.</p>
<p>Example:</p>
<p>User is typing as URL:</p>
<pre><code>http://www.sta
</code></pr... | 9 | 2008-11-01T15:50:30Z | 656,223 | <p>That control is often called a word wheel. MSDN has a recent <a href="http://msdn.microsoft.com/en-us/magazine/cc721610.aspx" rel="nofollow">walkthrough</a> on writing one with <code>LINQ</code>. There are two critical aspects: deferred execution and lazy evaluation. The article has source code too. </p>
| 0 | 2009-03-17T22:05:48Z | [
"python",
"autocomplete",
"autosuggest"
] |
Can I Use Python to Make a Delete Button in a 'web page' | 256,021 | <p>I have written a script that goes through a bunch of files and snips out a portion of the files for further processing. The script creates a new directory and creates new files for each snip that is taken out. I have to now evaluate each of the files that were created to see if it is what I needed. The script also... | 2 | 2008-11-01T19:52:08Z | 256,028 | <p>You would have to write the web page in Python. There are many Python web frameworks out there (e.g. Django) that are easy to work with. You could convert your entire scripting framework to a web application that has a worker thread going and crawling through html pages, saving them to a particular location, indexin... | 0 | 2008-11-01T19:59:48Z | [
"python",
"web-applications",
"browser"
] |
Can I Use Python to Make a Delete Button in a 'web page' | 256,021 | <p>I have written a script that goes through a bunch of files and snips out a portion of the files for further processing. The script creates a new directory and creates new files for each snip that is taken out. I have to now evaluate each of the files that were created to see if it is what I needed. The script also... | 2 | 2008-11-01T19:52:08Z | 256,031 | <p>Rather than having your script output static HTML files, with a little amount of work you could probably adapt your script to run as a small web application with the help of something like web.py.</p>
<p>You would start your script and point a browser at <a href="http://localhost:8080" rel="nofollow">http://localho... | 0 | 2008-11-01T20:00:43Z | [
"python",
"web-applications",
"browser"
] |
Can I Use Python to Make a Delete Button in a 'web page' | 256,021 | <p>I have written a script that goes through a bunch of files and snips out a portion of the files for further processing. The script creates a new directory and creates new files for each snip that is taken out. I have to now evaluate each of the files that were created to see if it is what I needed. The script also... | 2 | 2008-11-01T19:52:08Z | 256,040 | <p>You could make this even simpler by making it all happen in one main page. Instead of having a list of hyperlinks, just have the main page have one frame that loads one of the autocreated pages in it. Put a couple of buttons at the bottom - a "Keep this page" and a "Delete this page." When you click either button, t... | 1 | 2008-11-01T20:07:07Z | [
"python",
"web-applications",
"browser"
] |
Can I Use Python to Make a Delete Button in a 'web page' | 256,021 | <p>I have written a script that goes through a bunch of files and snips out a portion of the files for further processing. The script creates a new directory and creates new files for each snip that is taken out. I have to now evaluate each of the files that were created to see if it is what I needed. The script also... | 2 | 2008-11-01T19:52:08Z | 303,086 | <p>Well I finally found an answer that achieved what I wanted-I did not want to learn a new language-Python is hard enough given my lack or experience</p>
<pre><code>def OnDelete(self, event):
assert self.current, "invalid delete operation"
try:
os.remove(os.path.join(self.cwd, self.current))
</code></... | 0 | 2008-11-19T19:40:25Z | [
"python",
"web-applications",
"browser"
] |
Which exception should I raise on bad/illegal argument combinations in Python? | 256,222 | <p>I was wondering about the best practices for indicating invalid argument combinations in Python. I've come across a few situations where you have a function like so:</p>
<pre><code>def import_to_orm(name, save=False, recurse=False):
"""
:param name: Name of some external entity to import.
:param save: S... | 235 | 2008-11-01T23:02:36Z | 256,235 | <p>I've mostly just seen the builtin <code>ValueError</code> used in this situation.</p>
| 9 | 2008-11-01T23:17:40Z | [
"python",
"exception",
"arguments"
] |
Which exception should I raise on bad/illegal argument combinations in Python? | 256,222 | <p>I was wondering about the best practices for indicating invalid argument combinations in Python. I've come across a few situations where you have a function like so:</p>
<pre><code>def import_to_orm(name, save=False, recurse=False):
"""
:param name: Name of some external entity to import.
:param save: S... | 235 | 2008-11-01T23:02:36Z | 256,236 | <p>I would inherit from <code>ValueError</code></p>
<pre><code>class IllegalArgumentError(ValueError):
pass
</code></pre>
<p>It is sometimes better to create your own exceptions, but inherit from a built-in one, which is as close to what you want as possible.</p>
<p>If you need to catch that specific error, it i... | 40 | 2008-11-01T23:17:49Z | [
"python",
"exception",
"arguments"
] |
Which exception should I raise on bad/illegal argument combinations in Python? | 256,222 | <p>I was wondering about the best practices for indicating invalid argument combinations in Python. I've come across a few situations where you have a function like so:</p>
<pre><code>def import_to_orm(name, save=False, recurse=False):
"""
:param name: Name of some external entity to import.
:param save: S... | 235 | 2008-11-01T23:02:36Z | 256,239 | <p>I'm not sure I agree with inheritance from <code>ValueError</code> -- my interpretation of the documentation is that <code>ValueError</code> is <em>only</em> supposed to be raised by builtins... inheriting from it or raising it yourself seems incorrect.</p>
<blockquote>
<p>Raised when a built-in operation or
fu... | 2 | 2008-11-01T23:21:54Z | [
"python",
"exception",
"arguments"
] |
Which exception should I raise on bad/illegal argument combinations in Python? | 256,222 | <p>I was wondering about the best practices for indicating invalid argument combinations in Python. I've come across a few situations where you have a function like so:</p>
<pre><code>def import_to_orm(name, save=False, recurse=False):
"""
:param name: Name of some external entity to import.
:param save: S... | 235 | 2008-11-01T23:02:36Z | 256,260 | <p>I would just raise <a href="https://docs.python.org/2/library/exceptions.html#exceptions.ValueError">ValueError</a>, unless you need a more specific exception..</p>
<pre><code>def import_to_orm(name, save=False, recurse=False):
if recurse and not save:
raise ValueError("save must be True if recurse is T... | 243 | 2008-11-01T23:37:31Z | [
"python",
"exception",
"arguments"
] |
Python packages and egg-info directories | 256,417 | <p>Can someone explain how egg-info directories are tied to their respective modules? For example, I have the following:</p>
<pre><code>/usr/local/lib/python2.5/site-packages/quodlibet/
/usr/local/lib/python2.5/site-packages/quodlibet-2.0.egg-info/
</code></pre>
<p>I'm assuming the egg-info directory is to make the c... | 52 | 2008-11-02T02:26:20Z | 256,614 | <p>The .egg-info directories get only created if --single-version-externally-managed was used to install the egg. "Normally", installing an egg would create a single directory (or zip file), containing both the code and the metadata. </p>
<p>pkg_resources (which is the library that reads the metadata) has a function <... | 46 | 2008-11-02T06:40:26Z | [
"python",
"setuptools",
"egg"
] |
Putting a pyCurl XML server response into a variable (Python) | 256,564 | <p>I'm a Python novice, trying to use pyCurl. The project I am working on is creating a Python wrapper for the twitpic.com API (<a href="http://twitpic.com/api.do" rel="nofollow">http://twitpic.com/api.do</a>). For reference purposes, check out the code (<a href="http://pastebin.com/f4c498b6e" rel="nofollow">http://pas... | 3 | 2008-11-02T05:38:48Z | 256,610 | <p><a href="http://pycurl.sourceforge.net/doc/curlobject.html" rel="nofollow">The pycurl doc</a> explicitly says:</p>
<blockquote>
<p>perform() -> None</p>
</blockquote>
<p>So the expected result is what you observe.</p>
<p>looking at an example from the pycurl site:</p>
<pre><code>import sys
import pycurl
class... | 4 | 2008-11-02T06:35:34Z | [
"python",
"xml",
"pycurl"
] |
Putting a pyCurl XML server response into a variable (Python) | 256,564 | <p>I'm a Python novice, trying to use pyCurl. The project I am working on is creating a Python wrapper for the twitpic.com API (<a href="http://twitpic.com/api.do" rel="nofollow">http://twitpic.com/api.do</a>). For reference purposes, check out the code (<a href="http://pastebin.com/f4c498b6e" rel="nofollow">http://pas... | 3 | 2008-11-02T05:38:48Z | 2,351,363 | <p>Using a StringIO would be much cleaner, no point in using a dummy class like that if all you want is the response data...</p>
<p>Something like this would suffice:</p>
<pre><code>import pycurl
import cStringIO
response = cStringIO.StringIO()
c = pycurl.Curl()
c.setopt(c.URL, 'http://www.turnkeylinux.org')
c.seto... | 12 | 2010-02-28T14:42:24Z | [
"python",
"xml",
"pycurl"
] |
Message Box in Python | 257,398 | <p>Is there a UI library to create a message box or input box in python?</p>
| 6 | 2008-11-02T21:22:30Z | 257,403 | <p>Your best bet is the tkMessageBox module, which should work on all systems (as Python will typically come with Tkinter).</p>
<p>If you can restrict yourself to a specific operating system, better choices might be available.</p>
| 11 | 2008-11-02T21:26:54Z | [
"python",
"user-controls",
"user-interface"
] |
Message Box in Python | 257,398 | <p>Is there a UI library to create a message box or input box in python?</p>
| 6 | 2008-11-02T21:22:30Z | 257,532 | <p>I've heard good things about wx python, which is also multi-platform. </p>
| 2 | 2008-11-02T22:58:15Z | [
"python",
"user-controls",
"user-interface"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.