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
Extending Python with C/C++
1,076,300
<p>Can anyone please give me tips on the tools or sofware to use to extend Python with C/C++? Thanks.</p>
4
2009-07-02T19:42:30Z
1,076,321
<p>The Python website itself has a great <a href="http://docs.python.org/extending/">set of examples</a>, as well as <a href="http://docs.python.org/c-api/">API documentation</a>. That's literally all I used when I needed to write C extensions.</p>
10
2009-07-02T19:46:35Z
[ "c++", "python", "c" ]
Extending Python with C/C++
1,076,300
<p>Can anyone please give me tips on the tools or sofware to use to extend Python with C/C++? Thanks.</p>
4
2009-07-02T19:42:30Z
1,076,324
<p>Yes, you need this: <a href="http://www.python.org/doc/ext/" rel="nofollow">http://www.python.org/doc/ext/</a></p> <p>And of course also a C/C++ compiler.</p> <p>If you describe what you are trying to do, and what kind of extensions you are making I'm sure people can give you more info.</p> <p>There are things li...
2
2009-07-02T19:46:55Z
[ "c++", "python", "c" ]
Extending Python with C/C++
1,076,300
<p>Can anyone please give me tips on the tools or sofware to use to extend Python with C/C++? Thanks.</p>
4
2009-07-02T19:42:30Z
1,076,328
<p>I'll add the obligatory reference to <a href="http://www.boost.org/doc/libs/1%5F39%5F0/libs/python/doc/index.html">Boost.Python</a> for C++ stuff.</p>
13
2009-07-02T19:47:25Z
[ "c++", "python", "c" ]
Extending Python with C/C++
1,076,300
<p>Can anyone please give me tips on the tools or sofware to use to extend Python with C/C++? Thanks.</p>
4
2009-07-02T19:42:30Z
1,076,339
<p>Maybe <a href="http://github.com/felipec/libmtag-python/tree/master" rel="nofollow">this example</a> helps. I think it's simple enough :)</p>
1
2009-07-02T19:49:24Z
[ "c++", "python", "c" ]
Extending Python with C/C++
1,076,300
<p>Can anyone please give me tips on the tools or sofware to use to extend Python with C/C++? Thanks.</p>
4
2009-07-02T19:42:30Z
1,077,436
<p>There are many solutions. In general, you should avoid it if possible, as writing C extensions is tedious. Often, it is necessary to use a 3rd party library. In that case, I think the winning solution today is <a href="http://www.cython.org/" rel="nofollow">cython</a>.</p> <p>Cython is a languages which "looks like...
2
2009-07-03T01:21:25Z
[ "c++", "python", "c" ]
Extending Python with C/C++
1,076,300
<p>Can anyone please give me tips on the tools or sofware to use to extend Python with C/C++? Thanks.</p>
4
2009-07-02T19:42:30Z
1,077,488
<p>I see nobody's yet pointed out one of my favorite solutions for wrapping C++ code, <a href="http://www.riverbankcomputing.co.uk/software/sip/intro">SIP</a> (I believe it also works for wrapping C, like SWIG and unlike Boost, but I've never used it that way). It's the tool Riverbank Software developed to make PyQt, t...
6
2009-07-03T01:47:01Z
[ "c++", "python", "c" ]
Extending Python with C/C++
1,076,300
<p>Can anyone please give me tips on the tools or sofware to use to extend Python with C/C++? Thanks.</p>
4
2009-07-02T19:42:30Z
1,077,933
<p>I've used <a href="http://cxx.sourceforge.net/" rel="nofollow">pycxx</a> in the past and I've really enjoyed to use this lib. </p> <p>In my opinion, it is easier to use than SWIG. I can't really compare to boost.python because I've never really used boost. I think that pycxx is lighter than boost.python but I may b...
3
2009-07-03T05:58:45Z
[ "c++", "python", "c" ]
Replacing values in a Python list/dictionary?
1,076,536
<p>Ok, I am trying to filter a list/dictionary passed to me and "clean" it up a bit, as there are certain values in it that I need to get rid of.</p> <p>So, if it's looking like this:</p> <pre><code>"records": [{"key1": "AAA", "key2": "BBB", "key3": "CCC", "key4": "AAA"...}] </code></pre> <p>How would I quickly and ...
19
2009-07-02T20:29:28Z
1,076,567
<pre><code>dic = root['records'][0] for i, j in dic.items(): # use iteritems in py2k if j == 'AAA': dic[i] = 'xxx' </code></pre>
9
2009-07-02T20:38:05Z
[ "python", "list", "dictionary", "replace" ]
Replacing values in a Python list/dictionary?
1,076,536
<p>Ok, I am trying to filter a list/dictionary passed to me and "clean" it up a bit, as there are certain values in it that I need to get rid of.</p> <p>So, if it's looking like this:</p> <pre><code>"records": [{"key1": "AAA", "key2": "BBB", "key3": "CCC", "key4": "AAA"...}] </code></pre> <p>How would I quickly and ...
19
2009-07-02T20:29:28Z
1,076,577
<pre><code>DATA = {"records": [{"key1": "AAA", "key2": "BBB", "key3": "CCC", "key4": "AAA"}]} for name, datalist in DATA.iteritems(): # Or items() in Python 3.x for datadict in datalist: for key, value in datadict.items(): if value == "AAA": datadict[key] = "XXX" print (DATA) ...
26
2009-07-02T20:40:17Z
[ "python", "list", "dictionary", "replace" ]
Trouble using python PIL library to crop and save image
1,076,638
<p>Im attempting to crop a pretty high res image and save the result to make sure its completed. However I keep getting the following error regardless of how I use the save method: <code>SystemError: tile cannot extend outside image</code></p> <pre><code>from PIL import Image # size is width/height img = Image.open(...
27
2009-07-02T20:54:04Z
1,076,648
<p>The box is (left, upper, right, lower) so maybe you meant (2407, 804, 2407+71, 804+796)?</p> <p><strong>Edit</strong>: All four coordinates are measured from the top/left corner, and describe the distance from that corner to the left edge, top edge, right edge and bottom edge.</p> <p>Your code should look like thi...
46
2009-07-02T20:56:50Z
[ "python", "python-imaging-library" ]
Trouble using python PIL library to crop and save image
1,076,638
<p>Im attempting to crop a pretty high res image and save the result to make sure its completed. However I keep getting the following error regardless of how I use the save method: <code>SystemError: tile cannot extend outside image</code></p> <pre><code>from PIL import Image # size is width/height img = Image.open(...
27
2009-07-02T20:54:04Z
17,653,193
<p>Try this:</p> <p>it's a simple code to crop an image, and it works like a charm ;)</p> <pre><code>import Image def crop_image(input_image, output_image, start_x, start_y, width, height): """Pass input name image, output name image, x coordinate to start croping, y coordinate to start croping, width to crop, h...
10
2013-07-15T11:28:06Z
[ "python", "python-imaging-library" ]
Making a variable non-inheritable in python
1,076,718
<p>Is there a way to make a variable non-inheritable in python? Like in the following example: B is a subclass of A, but I want it to have its own SIZE value.</p> <p>Could I get an Error to be raised (on __init__ or on getsize()) if B doesn't override SIZE?</p> <pre><code>class A: SIZE = 5 def getsize(self): re...
3
2009-07-02T21:13:36Z
1,076,737
<p>Use a double-underscore prefix:</p> <p>(Double-underscore solution deleted after Emma's clarification)</p> <p>OK, you can do it like this:</p> <pre><code>class A: SIZE = 5 def __init__(self): if self.__class__ != A: del self.SIZE def getsize(self): return self.SIZE class ...
7
2009-07-02T21:17:31Z
[ "python", "inheritance" ]
Making a variable non-inheritable in python
1,076,718
<p>Is there a way to make a variable non-inheritable in python? Like in the following example: B is a subclass of A, but I want it to have its own SIZE value.</p> <p>Could I get an Error to be raised (on __init__ or on getsize()) if B doesn't override SIZE?</p> <pre><code>class A: SIZE = 5 def getsize(self): re...
3
2009-07-02T21:13:36Z
1,076,743
<p>You can always just override it like this:</p> <pre><code>class B(A): SIZE = 6 </code></pre>
0
2009-07-02T21:19:33Z
[ "python", "inheritance" ]
Making a variable non-inheritable in python
1,076,718
<p>Is there a way to make a variable non-inheritable in python? Like in the following example: B is a subclass of A, but I want it to have its own SIZE value.</p> <p>Could I get an Error to be raised (on __init__ or on getsize()) if B doesn't override SIZE?</p> <pre><code>class A: SIZE = 5 def getsize(self): re...
3
2009-07-02T21:13:36Z
1,076,793
<p>It sounds like what you want is a private variable. In which case this is what you need to do:</p> <pre><code>class A: __SIZE = 5 def getsize(self): return self.__SIZE def setsize(self,newsize): self.__SIZE=newsize class B(A): pass </code></pre>
0
2009-07-02T21:37:04Z
[ "python", "inheritance" ]
Making a variable non-inheritable in python
1,076,718
<p>Is there a way to make a variable non-inheritable in python? Like in the following example: B is a subclass of A, but I want it to have its own SIZE value.</p> <p>Could I get an Error to be raised (on __init__ or on getsize()) if B doesn't override SIZE?</p> <pre><code>class A: SIZE = 5 def getsize(self): re...
3
2009-07-02T21:13:36Z
1,076,798
<p>If you want to make <em>absolutely</em> sure that subclasses of <code>A</code> override <code>SIZE</code>, you could use a metaclass for <code>A</code> that will raise an error when a subclass does not override it (note that <code>A</code> is a new-style class here):</p> <pre><code>class ClassWithSize(type): de...
4
2009-07-02T21:38:27Z
[ "python", "inheritance" ]
Making a variable non-inheritable in python
1,076,718
<p>Is there a way to make a variable non-inheritable in python? Like in the following example: B is a subclass of A, but I want it to have its own SIZE value.</p> <p>Could I get an Error to be raised (on __init__ or on getsize()) if B doesn't override SIZE?</p> <pre><code>class A: SIZE = 5 def getsize(self): re...
3
2009-07-02T21:13:36Z
1,077,095
<p>Another approach might be to get classes A and B to inherit from a third class instead of one from the other:</p> <pre><code>class X: def getsize(self): return self.SIZE class A(X): SIZE = 5 class B(X): pass a = A() print a.getsize() # Prints 5 b = B() print b.getsize() # AttributeError: B instan...
0
2009-07-02T22:55:56Z
[ "python", "inheritance" ]
Making a variable non-inheritable in python
1,076,718
<p>Is there a way to make a variable non-inheritable in python? Like in the following example: B is a subclass of A, but I want it to have its own SIZE value.</p> <p>Could I get an Error to be raised (on __init__ or on getsize()) if B doesn't override SIZE?</p> <pre><code>class A: SIZE = 5 def getsize(self): re...
3
2009-07-02T21:13:36Z
1,077,309
<p>Another common idiom is to use <a href="http://docs.python.org/library/constants.html?highlight=notimplemented#NotImplemented" rel="nofollow">NotImplemented</a>. Think of it as the middle ground between metaclass enforcement and mere documentation.</p> <pre><code>class A: SIZE = NotImplemented </code></pre> <p...
0
2009-07-03T00:07:36Z
[ "python", "inheritance" ]
Making a variable non-inheritable in python
1,076,718
<p>Is there a way to make a variable non-inheritable in python? Like in the following example: B is a subclass of A, but I want it to have its own SIZE value.</p> <p>Could I get an Error to be raised (on __init__ or on getsize()) if B doesn't override SIZE?</p> <pre><code>class A: SIZE = 5 def getsize(self): re...
3
2009-07-02T21:13:36Z
1,077,513
<p>If metaclasses scare you (and I sympathize with that attitude!-), a descriptor could work -- you don't even have to make your custom descriptor (though that's <a href="http://users.rcn.com/python/download/Descriptor.htm" rel="nofollow">easy</a> enough), a plain good old property could work fine too:</p> <pre><code>...
1
2009-07-03T01:57:20Z
[ "python", "inheritance" ]
Making a variable non-inheritable in python
1,076,718
<p>Is there a way to make a variable non-inheritable in python? Like in the following example: B is a subclass of A, but I want it to have its own SIZE value.</p> <p>Could I get an Error to be raised (on __init__ or on getsize()) if B doesn't override SIZE?</p> <pre><code>class A: SIZE = 5 def getsize(self): re...
3
2009-07-02T21:13:36Z
1,077,535
<p>The only approach that I can add is to use <code>hasattr(self.__class__, 'SIZE')</code> in the implementation of <code>getsize()</code> and toss an exception if the attribute is not found. Something like:</p> <pre><code>class A: SIZE = 5 def getsize(self): klass = self.__class__ if hasattr(klass, 'S...
1
2009-07-03T02:14:41Z
[ "python", "inheritance" ]
One liner to replicate lines coming from a file (Python)
1,076,872
<p>I have a regular list comprehension to load all lines of a file in a list</p> <pre><code>f = open('file') try: self._raw = [L.rstrip('\n') for L in f] finally: f.close() </code></pre> <p>Now I'd like to insert in the list each line 'n' times on the fly. How to do it inside the list comprehension ?</p> <p...
1
2009-07-02T22:02:08Z
1,076,886
<pre><code>self._raw = [L.rstrip('\n') for L in f for _ in xrange(n)] </code></pre>
6
2009-07-02T22:05:13Z
[ "python", "list-comprehension" ]
urllib.urlopen isn't working. Is there a workaround?
1,076,958
<p>I'm getting a getaddress error and after doing some sleuthing, it looks like it might be my corporate intranet not allowing the connection (I'm assuming due to security, although it is strange that IE works but won't allow Python to open a url). Is there a safe way to get around this?</p> <p>Here's the exact error...
2
2009-07-02T22:25:44Z
1,076,969
<p>Check you are using the correct proxy.<br /> You can get the proxy information by using urllib.getproxies (note: getproxies does <em>not</em> work with dynamic proxy configuration, like when using PAC).</p> <p><strong>Update</strong> As per information about empty proxy list, I would suggest using an urlopener, wit...
3
2009-07-02T22:28:59Z
[ "python", "url" ]
urllib.urlopen isn't working. Is there a workaround?
1,076,958
<p>I'm getting a getaddress error and after doing some sleuthing, it looks like it might be my corporate intranet not allowing the connection (I'm assuming due to security, although it is strange that IE works but won't allow Python to open a url). Is there a safe way to get around this?</p> <p>Here's the exact error...
2
2009-07-02T22:25:44Z
1,077,370
<p>You probably need to fill in proxy information.</p> <pre><code>import urllib2 proxy_handler = urllib2.ProxyHandler({'http': 'http://yourcorporateproxy:12345/'}) proxy_auth_handler = urllib2.HTTPBasicAuthHandler() proxy_auth_handler.add_password('realm', 'host', 'username', 'password') opener = urllib2.build_opener...
7
2009-07-03T00:40:01Z
[ "python", "url" ]
urllib.urlopen isn't working. Is there a workaround?
1,076,958
<p>I'm getting a getaddress error and after doing some sleuthing, it looks like it might be my corporate intranet not allowing the connection (I'm assuming due to security, although it is strange that IE works but won't allow Python to open a url). Is there a safe way to get around this?</p> <p>Here's the exact error...
2
2009-07-02T22:25:44Z
1,077,594
<p>Possibly this is a DNS issue, try urlopen with the IP address of the web server you're accessing, i.e.</p> <pre><code>import urllib URL="http://66.102.11.99" # www.google.com f = urllib.urlopen(URL) f.read() </code></pre> <p>If this succeeds, then it's probably a DNS issue rather than a proxy issue (but you shou...
2
2009-07-03T02:53:07Z
[ "python", "url" ]
urllib.urlopen isn't working. Is there a workaround?
1,076,958
<p>I'm getting a getaddress error and after doing some sleuthing, it looks like it might be my corporate intranet not allowing the connection (I'm assuming due to security, although it is strange that IE works but won't allow Python to open a url). Is there a safe way to get around this?</p> <p>Here's the exact error...
2
2009-07-02T22:25:44Z
1,077,784
<p>Looks like a DNS problem. </p> <p>Since you are using Windows, you can try run this command</p> <pre><code>nslookup www.google.com </code></pre> <p>To check if the web address can be resolved successfully.</p> <p>If not, it is a network setting issue</p> <p>If OK, then we have to look at possible alternative ca...
2
2009-07-03T04:43:49Z
[ "python", "url" ]
urllib.urlopen isn't working. Is there a workaround?
1,076,958
<p>I'm getting a getaddress error and after doing some sleuthing, it looks like it might be my corporate intranet not allowing the connection (I'm assuming due to security, although it is strange that IE works but won't allow Python to open a url). Is there a safe way to get around this?</p> <p>Here's the exact error...
2
2009-07-02T22:25:44Z
1,152,582
<p>I was facing the same issue. In my system the proxy configuration is through a .PAC file. So i opended that file, took out the default proxy url, for me it was <a href="http://168.219.61.250:8080/" rel="nofollow">http://168.219.61.250:8080/</a></p> <p>Following test code worked for me :</p> <pre><code>import urlli...
2
2009-07-20T09:25:52Z
[ "python", "url" ]
python list comprehensions; compressing a list of lists?
1,077,015
<p>guys. I'm trying to find the most elegant solution to a problem and wondered if python has anything built-in for what I'm trying to do. </p> <p>What I'm doing is this. I have a list, <code>A</code>, and I have a function <code>f</code> which takes an item and returns a list. I can use a list comprehension to conver...
35
2009-07-02T22:40:40Z
1,077,061
<p>You could try <code>itertools.chain()</code>, like this:</p> <pre><code>import itertools import os dirs = ["c:\\usr", "c:\\temp"] subs = list(itertools.chain(*[os.listdir(d) for d in dirs])) print subs </code></pre> <p><code>itertools.chain()</code> returns an iterator, hence the passing to <code>list()</code>.</p...
3
2009-07-02T22:47:52Z
[ "functional-programming", "python", "list-comprehension" ]
python list comprehensions; compressing a list of lists?
1,077,015
<p>guys. I'm trying to find the most elegant solution to a problem and wondered if python has anything built-in for what I'm trying to do. </p> <p>What I'm doing is this. I have a list, <code>A</code>, and I have a function <code>f</code> which takes an item and returns a list. I can use a list comprehension to conver...
35
2009-07-02T22:40:40Z
1,077,067
<pre><code>subs = [] map(subs.extend, (os.listdir(d) for d in dirs)) </code></pre> <p>(but Ants's answer is better; +1 for him)</p>
5
2009-07-02T22:48:38Z
[ "functional-programming", "python", "list-comprehension" ]
python list comprehensions; compressing a list of lists?
1,077,015
<p>guys. I'm trying to find the most elegant solution to a problem and wondered if python has anything built-in for what I'm trying to do. </p> <p>What I'm doing is this. I have a list, <code>A</code>, and I have a function <code>f</code> which takes an item and returns a list. I can use a list comprehension to conver...
35
2009-07-02T22:40:40Z
1,077,074
<p>You can find a good answer in <a href="http://docs.python.org/library/itertools.html#recipes">itertools' recipes:</a></p> <pre><code>def flatten(listOfLists): return list(chain.from_iterable(listOfLists)) </code></pre> <p>(Note: requires Python 2.6+)</p>
35
2009-07-02T22:50:47Z
[ "functional-programming", "python", "list-comprehension" ]
python list comprehensions; compressing a list of lists?
1,077,015
<p>guys. I'm trying to find the most elegant solution to a problem and wondered if python has anything built-in for what I'm trying to do. </p> <p>What I'm doing is this. I have a list, <code>A</code>, and I have a function <code>f</code> which takes an item and returns a list. I can use a list comprehension to conver...
35
2009-07-02T22:40:40Z
1,077,081
<p>Google brought me next solution:</p> <pre><code>def flatten(l): if isinstance(l,list): return sum(map(flatten,l)) else: return l </code></pre>
3
2009-07-02T22:52:51Z
[ "functional-programming", "python", "list-comprehension" ]
python list comprehensions; compressing a list of lists?
1,077,015
<p>guys. I'm trying to find the most elegant solution to a problem and wondered if python has anything built-in for what I'm trying to do. </p> <p>What I'm doing is this. I have a list, <code>A</code>, and I have a function <code>f</code> which takes an item and returns a list. I can use a list comprehension to conver...
35
2009-07-02T22:40:40Z
1,077,205
<p>You can have nested iterations in a single list comprehension:</p> <pre><code>[filename for path in dirs for filename in os.listdir(path)] </code></pre>
58
2009-07-02T23:32:56Z
[ "functional-programming", "python", "list-comprehension" ]
python list comprehensions; compressing a list of lists?
1,077,015
<p>guys. I'm trying to find the most elegant solution to a problem and wondered if python has anything built-in for what I'm trying to do. </p> <p>What I'm doing is this. I have a list, <code>A</code>, and I have a function <code>f</code> which takes an item and returns a list. I can use a list comprehension to conver...
35
2009-07-02T22:40:40Z
1,077,220
<p>You could just do the straightforward:</p> <pre><code>subs = [] for d in dirs: subs.extend(os.listdir(d)) </code></pre>
11
2009-07-02T23:37:11Z
[ "functional-programming", "python", "list-comprehension" ]
python list comprehensions; compressing a list of lists?
1,077,015
<p>guys. I'm trying to find the most elegant solution to a problem and wondered if python has anything built-in for what I'm trying to do. </p> <p>What I'm doing is this. I have a list, <code>A</code>, and I have a function <code>f</code> which takes an item and returns a list. I can use a list comprehension to conver...
35
2009-07-02T22:40:40Z
1,079,210
<p>You can concatenate lists using the normal addition operator:</p> <pre><code>&gt;&gt;&gt; [1, 2] + [3, 4] [1, 2, 3, 4] </code></pre> <p>The built-in function <code>sum</code> will add the numbers in a sequence and can optionally start from a specific value:</p> <pre><code>&gt;&gt;&gt; sum(xrange(10), 100) 145 </c...
10
2009-07-03T12:47:57Z
[ "functional-programming", "python", "list-comprehension" ]
python list comprehensions; compressing a list of lists?
1,077,015
<p>guys. I'm trying to find the most elegant solution to a problem and wondered if python has anything built-in for what I'm trying to do. </p> <p>What I'm doing is this. I have a list, <code>A</code>, and I have a function <code>f</code> which takes an item and returns a list. I can use a list comprehension to conver...
35
2009-07-02T22:40:40Z
2,082,107
<pre><code>&gt;&gt;&gt; listOfLists = [[1, 2],[3, 4, 5], [6]] &gt;&gt;&gt; reduce(list.__add__, listOfLists) [1, 2, 3, 4, 5, 6] </code></pre> <p>I'm guessing the itertools solution is more efficient than this, but this feel very pythonic and avoids having to import a library just for the sake of a single list operatio...
25
2010-01-17T18:32:30Z
[ "functional-programming", "python", "list-comprehension" ]
python list comprehensions; compressing a list of lists?
1,077,015
<p>guys. I'm trying to find the most elegant solution to a problem and wondered if python has anything built-in for what I'm trying to do. </p> <p>What I'm doing is this. I have a list, <code>A</code>, and I have a function <code>f</code> which takes an item and returns a list. I can use a list comprehension to conver...
35
2009-07-02T22:40:40Z
13,498,063
<pre><code>import itertools x=[['b11','b12'],['b21','b22'],['b31']] y=list(itertools.chain(*x)) print y </code></pre> <p>itertools will work from python2.3 and greater</p>
4
2012-11-21T16:48:02Z
[ "functional-programming", "python", "list-comprehension" ]
python list comprehensions; compressing a list of lists?
1,077,015
<p>guys. I'm trying to find the most elegant solution to a problem and wondered if python has anything built-in for what I'm trying to do. </p> <p>What I'm doing is this. I have a list, <code>A</code>, and I have a function <code>f</code> which takes an item and returns a list. I can use a list comprehension to conver...
35
2009-07-02T22:40:40Z
20,037,408
<p>The question proposed <code>flatmap</code>. Some implementations are proposed but they may unnecessary creating intermediate lists. Here is one implementation that's base on iterators.</p> <pre><code>def flatmap(func, *iterable): return itertools.chain.from_iterable(map(func, *iterable)) In [148]: list(flatmap...
9
2013-11-17T23:07:11Z
[ "functional-programming", "python", "list-comprehension" ]
python list comprehensions; compressing a list of lists?
1,077,015
<p>guys. I'm trying to find the most elegant solution to a problem and wondered if python has anything built-in for what I'm trying to do. </p> <p>What I'm doing is this. I have a list, <code>A</code>, and I have a function <code>f</code> which takes an item and returns a list. I can use a list comprehension to conver...
35
2009-07-02T22:40:40Z
31,489,364
<pre><code>If listA=[list1,list2,list3] flattened_list=reduce(lambda x,y:x+y,listA) </code></pre> <p>This will do.</p>
0
2015-07-18T08:39:41Z
[ "functional-programming", "python", "list-comprehension" ]
How do I store multiple values in a single attribute
1,077,227
<p>I don't know if I'm thinking of this the right way, and perhaps somebody will set me straight.</p> <p>Let's say I have a models.py that contains this:</p> <pre><code>class Order(models.Model): customer = models.foreignKey(Customer) total = models.charField(max_length=10) has_shipped = models.booleanField() ...
1
2009-07-02T23:38:14Z
1,077,245
<p>You can create one more model which will serve as many-to-many relationship between Order and Products</p> <p>something like this</p> <pre><code>class OrderProducts(models.Model) product = models.ForeignKey(Product) order = models.ForeignKey(Order) </code></pre>
0
2009-07-02T23:45:30Z
[ "python", "django", "e-commerce" ]
How do I store multiple values in a single attribute
1,077,227
<p>I don't know if I'm thinking of this the right way, and perhaps somebody will set me straight.</p> <p>Let's say I have a models.py that contains this:</p> <pre><code>class Order(models.Model): customer = models.foreignKey(Customer) total = models.charField(max_length=10) has_shipped = models.booleanField() ...
1
2009-07-02T23:38:14Z
1,077,253
<p>What you're after is a many to many relationship between product and order.</p> <p>Something like:</p> <pre><code>class Order(models.Model): customer = models.foreignKey(Customer) total = models.charField(max_length=10) has_shipped = models.booleanField() products = models.ManyToManyField(Product) </code><...
7
2009-07-02T23:48:41Z
[ "python", "django", "e-commerce" ]
How to specify time zone (UTC) when converting to Unix time? (Python)
1,077,285
<p>I have a utc timestamp in the IS8601 format and am trying to convert it to unix time. This is my console session:</p> <pre><code>In [9]: mydate Out[9]: '2009-07-17T01:21:00.000Z' In [10]: parseddate = iso8601.parse_date(mydate) In [14]: ti = time.mktime(parseddate.timetuple()) In [25]: datetime.datetime.utcfromti...
5
2009-07-03T00:00:45Z
1,077,313
<p>I am just guessing, but one hour difference can be not because of time zones, but because of daylight savings on/off.</p>
0
2009-07-03T00:09:28Z
[ "python", "datetime", "iso8601", "unix-timestamp" ]
How to specify time zone (UTC) when converting to Unix time? (Python)
1,077,285
<p>I have a utc timestamp in the IS8601 format and am trying to convert it to unix time. This is my console session:</p> <pre><code>In [9]: mydate Out[9]: '2009-07-17T01:21:00.000Z' In [10]: parseddate = iso8601.parse_date(mydate) In [14]: ti = time.mktime(parseddate.timetuple()) In [25]: datetime.datetime.utcfromti...
5
2009-07-03T00:00:45Z
1,077,362
<p>You can create an <code>struct_time</code> in UTC with <a href="http://docs.python.org/library/datetime.html#datetime.datetime.utctimetuple"><code>datetime.utctimetuple()</code></a> and then convert this to a unix timestamp with <a href="http://docs.python.org/library/calendar.html#calendar.timegm"><code>calendar.ti...
12
2009-07-03T00:33:03Z
[ "python", "datetime", "iso8601", "unix-timestamp" ]
How to specify time zone (UTC) when converting to Unix time? (Python)
1,077,285
<p>I have a utc timestamp in the IS8601 format and am trying to convert it to unix time. This is my console session:</p> <pre><code>In [9]: mydate Out[9]: '2009-07-17T01:21:00.000Z' In [10]: parseddate = iso8601.parse_date(mydate) In [14]: ti = time.mktime(parseddate.timetuple()) In [25]: datetime.datetime.utcfromti...
5
2009-07-03T00:00:45Z
13,423,441
<pre><code>naive_utc_dt = parseddate.replace(tzinfo=None) timestamp = (naive_utc_dt - datetime(1970, 1, 1)).total_seconds() # -&gt; 1247793660.0 </code></pre> <p>See more details in <a href="http://stackoverflow.com/a/8778548/4279">another answer to similar question</a>.</p> <p>And back:</p> <pre><code>utc_dt = date...
0
2012-11-16T19:50:49Z
[ "python", "datetime", "iso8601", "unix-timestamp" ]
Why is there no first(iterable) built-in function in Python?
1,077,307
<p>I'm wondering if there's a reason that there's no <code>first(iterable)</code> in the Python built-in functions, somewhat similar to <code>any(iterable)</code> and <code>all(iterable)</code> (it may be tucked in a stdlib module somewhere, but I don't see it in <code>itertools</code>). <code>first</code> would perfor...
54
2009-07-03T00:07:07Z
1,077,320
<p>If you have an iterator, you can just call its <code>next</code> method. Something like:</p> <pre><code>In [3]: (5*x for x in xrange(2,4)).next() Out[3]: 10 </code></pre>
39
2009-07-03T00:18:22Z
[ "python", "iterator", "generator" ]
Why is there no first(iterable) built-in function in Python?
1,077,307
<p>I'm wondering if there's a reason that there's no <code>first(iterable)</code> in the Python built-in functions, somewhat similar to <code>any(iterable)</code> and <code>all(iterable)</code> (it may be tucked in a stdlib module somewhere, but I don't see it in <code>itertools</code>). <code>first</code> would perfor...
54
2009-07-03T00:07:07Z
1,077,330
<p>Haskell makes use of what you just described, as the function <code>take</code> (or as the partial function <code>take 1</code>, technically). <a href="http://my.safaribooksonline.com/0596001673/pythoncook-CHP-17-SECT-12" rel="nofollow">Python Cookbook</a> has generator-wrappers written that perform the same functi...
4
2009-07-03T00:22:29Z
[ "python", "iterator", "generator" ]
Why is there no first(iterable) built-in function in Python?
1,077,307
<p>I'm wondering if there's a reason that there's no <code>first(iterable)</code> in the Python built-in functions, somewhat similar to <code>any(iterable)</code> and <code>all(iterable)</code> (it may be tucked in a stdlib module somewhere, but I don't see it in <code>itertools</code>). <code>first</code> would perfor...
54
2009-07-03T00:07:07Z
1,077,369
<p>There's some ambiguity in your question. Your definition of <strong>first</strong> and the regex example imply that there is a boolean test. But the denominators example explicitly has an if clause; so it's only a coincidence that each integer happens to be true.</p> <p>It looks like the combination of next and ...
6
2009-07-03T00:38:09Z
[ "python", "iterator", "generator" ]
Why is there no first(iterable) built-in function in Python?
1,077,307
<p>I'm wondering if there's a reason that there's no <code>first(iterable)</code> in the Python built-in functions, somewhat similar to <code>any(iterable)</code> and <code>all(iterable)</code> (it may be tucked in a stdlib module somewhere, but I don't see it in <code>itertools</code>). <code>first</code> would perfor...
54
2009-07-03T00:07:07Z
16,174,249
<p>There's a <a href="https://pypi.python.org/pypi/first">Pypi package called “first”</a> that does this:</p> <pre><code>&gt;&gt;&gt; from first import first &gt;&gt;&gt; first([0, None, False, [], (), 42]) 42 </code></pre> <p>Here's how you would use to return the first odd number, for example:</p> <pre><code>&...
13
2013-04-23T16:11:47Z
[ "python", "iterator", "generator" ]
Why is there no first(iterable) built-in function in Python?
1,077,307
<p>I'm wondering if there's a reason that there's no <code>first(iterable)</code> in the Python built-in functions, somewhat similar to <code>any(iterable)</code> and <code>all(iterable)</code> (it may be tucked in a stdlib module somewhere, but I don't see it in <code>itertools</code>). <code>first</code> would perfor...
54
2009-07-03T00:07:07Z
18,226,144
<p>I asked a <a href="http://stackoverflow.com/questions/18208730/shortcut-or-chain-applied-on-list">similar question</a> recently (it got marked as a duplicate of this question by now). My concern also was that I'd liked to use built-ins <em>only</em> to solve the problem of finding the first true value of a generato...
8
2013-08-14T07:58:09Z
[ "python", "iterator", "generator" ]
Why is there no first(iterable) built-in function in Python?
1,077,307
<p>I'm wondering if there's a reason that there's no <code>first(iterable)</code> in the Python built-in functions, somewhat similar to <code>any(iterable)</code> and <code>all(iterable)</code> (it may be tucked in a stdlib module somewhere, but I don't see it in <code>itertools</code>). <code>first</code> would perfor...
54
2009-07-03T00:07:07Z
18,589,970
<p>There is a "slice" iterator in itertools. It emulates the slice operations that we're familiar with in python. What you're looking for is something similar to this:</p> <pre><code>myList = [0,1,2,3,4,5] firstValue = myList[:1] </code></pre> <p>The equivalent using itertools for iterators:</p> <pre><code>from iter...
3
2013-09-03T10:30:54Z
[ "python", "iterator", "generator" ]
Why is there no first(iterable) built-in function in Python?
1,077,307
<p>I'm wondering if there's a reason that there's no <code>first(iterable)</code> in the Python built-in functions, somewhat similar to <code>any(iterable)</code> and <code>all(iterable)</code> (it may be tucked in a stdlib module somewhere, but I don't see it in <code>itertools</code>). <code>first</code> would perfor...
54
2009-07-03T00:07:07Z
36,981,241
<p>Just use star unpacking in Python 3.4 for the last elements, then you got your first element.</p> <pre><code>x = [0, 1, 2, 3] first, *rest = x print(first) print(rest) </code></pre> <p>This is supported since Python 3.5. Read the PEP: <a href="https://www.python.org/dev/peps/pep-0448/" rel="nofollow">https://www.p...
-1
2016-05-02T11:22:55Z
[ "python", "iterator", "generator" ]
Python Unix time doesn't work in Javascript
1,077,393
<p>In Python, using calendar.timegm(), I get a 10 digit result for a unix timestamp. When I put this into Javscript's setTime() function, it comes up with a date in 1970. It evidently needs a unix timestamp that is 13 digits long. How can this happen? Are they both counting from the same date? </p> <p>How can I use th...
6
2009-07-03T00:55:59Z
1,077,401
<p>Are you possibly mixing up seconds-since-1970 with milliseconds-since-1970?</p>
2
2009-07-03T00:59:42Z
[ "javascript", "python", "datetime", "utc", "unix-timestamp" ]
Python Unix time doesn't work in Javascript
1,077,393
<p>In Python, using calendar.timegm(), I get a 10 digit result for a unix timestamp. When I put this into Javscript's setTime() function, it comes up with a date in 1970. It evidently needs a unix timestamp that is 13 digits long. How can this happen? Are they both counting from the same date? </p> <p>How can I use th...
6
2009-07-03T00:55:59Z
1,077,402
<p>JavaScript <a href="https://developer.mozilla.org/en/Core%5FJavaScript%5F1.5%5FReference/Global%5FObjects/Date" rel="nofollow">Date constructor</a> works with milliseconds, you should multiply the Python unix time by 1000.</p> <pre><code>var unixTimestampSeg = 1247793660; var date = new Date(unixTimestampSeg*1000);...
1
2009-07-03T01:00:10Z
[ "javascript", "python", "datetime", "utc", "unix-timestamp" ]
Python Unix time doesn't work in Javascript
1,077,393
<p>In Python, using calendar.timegm(), I get a 10 digit result for a unix timestamp. When I put this into Javscript's setTime() function, it comes up with a date in 1970. It evidently needs a unix timestamp that is 13 digits long. How can this happen? Are they both counting from the same date? </p> <p>How can I use th...
6
2009-07-03T00:55:59Z
1,077,403
<p>timegm is based on Unix's <a href="http://linux.about.com/library/cmd/blcmdl3%5Fgmtime.htm">gmtime()</a> method, which return seconds since Jan 1, 1970.</p> <p>Javascripts <a href="http://www.w3schools.com/jsref/jsref%5FsetTime.asp">setTime()</a> method is milliseconds since that date. You'll need to multiply your...
11
2009-07-03T01:00:52Z
[ "javascript", "python", "datetime", "utc", "unix-timestamp" ]
Python Unix time doesn't work in Javascript
1,077,393
<p>In Python, using calendar.timegm(), I get a 10 digit result for a unix timestamp. When I put this into Javscript's setTime() function, it comes up with a date in 1970. It evidently needs a unix timestamp that is 13 digits long. How can this happen? Are they both counting from the same date? </p> <p>How can I use th...
6
2009-07-03T00:55:59Z
1,077,414
<p>Here are a couple of python methods I use to convert to and from javascript/datetime.</p> <pre><code>def to_datetime(js_timestamp): return datetime.datetime.fromtimestamp(js_timestamp/1000) def js_timestamp_from_datetime(dt): return 1000 * time.mktime(dt.timetuple()) </code></pre> <p>In javascript you wo...
8
2009-07-03T01:07:04Z
[ "javascript", "python", "datetime", "utc", "unix-timestamp" ]
Python Unicode UnicodeEncodeError
1,077,564
<p>I am having issues with trying to convert an UTF-8 string to unicode. I get the error.</p> <pre><code>UnicodeEncodeError: 'ascii' codec can't encode characters in position 73-75: ordinal not in range(128) </code></pre> <p>I tried wrapping this in a <code>try</code>/<code>except</code> block but then google was giv...
1
2009-07-03T02:33:04Z
1,077,575
<p>Try this:</p> <pre><code>self.response.headers['Location'] = absolute_url.decode("utf-8") or self.response.headers['Location'] = unicode(absolute_url, "utf-8") </code></pre>
-1
2009-07-03T02:40:16Z
[ "python", "google-app-engine", "unicode", "utf-8" ]
Python Unicode UnicodeEncodeError
1,077,564
<p>I am having issues with trying to convert an UTF-8 string to unicode. I get the error.</p> <pre><code>UnicodeEncodeError: 'ascii' codec can't encode characters in position 73-75: ordinal not in range(128) </code></pre> <p>I tried wrapping this in a <code>try</code>/<code>except</code> block but then google was giv...
1
2009-07-03T02:33:04Z
1,077,582
<p>Please edit that mess so that it's legible. Hint: use the "code block" (101010 thingy button).</p> <p>You say that you are "trying to convert an UTF-8 string to unicode" but <code>str(absolute_url)</code> is a strange way of going about it. Are you sure that <code>absolute_url</code> is UTF-8? Try </p> <pre><code...
1
2009-07-03T02:45:36Z
[ "python", "google-app-engine", "unicode", "utf-8" ]
Python Unicode UnicodeEncodeError
1,077,564
<p>I am having issues with trying to convert an UTF-8 string to unicode. I get the error.</p> <pre><code>UnicodeEncodeError: 'ascii' codec can't encode characters in position 73-75: ordinal not in range(128) </code></pre> <p>I tried wrapping this in a <code>try</code>/<code>except</code> block but then google was giv...
1
2009-07-03T02:33:04Z
1,077,590
<p>The location header you are trying to set needs to be an Url, and an Url needs to be in Ascii. Since your Url is not an Ascii string you get the error. Just catching the error won't help since the Location header won't work with an invalid Url.</p> <p>When you create <code>absolute_url</code> you need to make sure ...
4
2009-07-03T02:51:38Z
[ "python", "google-app-engine", "unicode", "utf-8" ]
Python Unicode UnicodeEncodeError
1,077,564
<p>I am having issues with trying to convert an UTF-8 string to unicode. I get the error.</p> <pre><code>UnicodeEncodeError: 'ascii' codec can't encode characters in position 73-75: ordinal not in range(128) </code></pre> <p>I tried wrapping this in a <code>try</code>/<code>except</code> block but then google was giv...
1
2009-07-03T02:33:04Z
1,077,646
<p>The correct <a href="http://www.nabble.com/Re:-Problem:-neither-urllib2.quote-nor-urllib.quote-encode-the--unicode-strings-arguments-p19823144.html">solution</a> is to do the following:</p> <pre><code>self.response.headers['Location'] = urllib.quote(absolute_url.encode("utf-8")) </code></pre>
8
2009-07-03T03:22:24Z
[ "python", "google-app-engine", "unicode", "utf-8" ]
Windows Application Programming & wxPython
1,077,649
<p>Developing a project of mine I realize I have a need for some level of persistence across sessions, for example when a user executes the application, changes some preferences and then closes the app. The next time the user executes the app, be it after a reboot or 15 minutes, I would like to be able to retain the p...
1
2009-07-03T03:24:31Z
1,077,657
<p>There are different methods to do this that have evolved over the years.</p> <p>These methods include (but not limited to):</p> <ol> <li>Registry entries.</li> <li>INI files.</li> <li>XML Files</li> <li>Simple binary/text files</li> <li>Databases</li> </ol> <p>Nowadays, most people do this kind of thing with XML ...
1
2009-07-03T03:28:49Z
[ "python", "windows", "wxpython" ]
Windows Application Programming & wxPython
1,077,649
<p>Developing a project of mine I realize I have a need for some level of persistence across sessions, for example when a user executes the application, changes some preferences and then closes the app. The next time the user executes the app, be it after a reboot or 15 minutes, I would like to be able to retain the p...
1
2009-07-03T03:24:31Z
1,077,697
<p>I would advice to do it in two steps.</p> <ol> <li><p>First step is to save your prefs. as string, for that you can</p> <p>a) Use any xml lib or output xml by hand to output string and read similarly from string</p> <p>b) Just use pickle module to dump your prefs object as a string</p> <p>c) Somehow genera...
3
2009-07-03T03:58:40Z
[ "python", "windows", "wxpython" ]
How to open a file on app engine patch?
1,077,691
<p>I tried to read a file in a view like this:</p> <pre><code>def foo(request): f = open('foo.txt', 'r') data = f.read() return HttpResponse(data) </code></pre> <p>I tried to place the foo.txt in almost every folder in the project but it still returns</p> <blockquote> <p>[Errno 2] No such file or direc...
0
2009-07-03T03:54:38Z
1,077,743
<p>In App Engine, patch or otherwise, you should be able to open (read-only) any file that gets uploaded with your app's sources. Is 'foo.txt' in the same directory as the py file? Does it get uploaded (what does your app.yaml say?)?</p>
2
2009-07-03T04:19:23Z
[ "python", "django", "google-app-engine" ]
How to open a file on app engine patch?
1,077,691
<p>I tried to read a file in a view like this:</p> <pre><code>def foo(request): f = open('foo.txt', 'r') data = f.read() return HttpResponse(data) </code></pre> <p>I tried to place the foo.txt in almost every folder in the project but it still returns</p> <blockquote> <p>[Errno 2] No such file or direc...
0
2009-07-03T03:54:38Z
2,678,621
<p>You should try f = open('./foo.txt', 'r')</p>
0
2010-04-20T21:06:15Z
[ "python", "django", "google-app-engine" ]
How to open a file on app engine patch?
1,077,691
<p>I tried to read a file in a view like this:</p> <pre><code>def foo(request): f = open('foo.txt', 'r') data = f.read() return HttpResponse(data) </code></pre> <p>I tried to place the foo.txt in almost every folder in the project but it still returns</p> <blockquote> <p>[Errno 2] No such file or direc...
0
2009-07-03T03:54:38Z
3,108,688
<p>Put './' in front of your file path:</p> <pre><code>f = open('./foo.txt') </code></pre> <p>If you don't, it will still work in App Engine Launcher 1.3.4, which could be confusing, but once you upload it, you'll get an error.</p> <p>Also it seems that you shouldn't mention the file (or its dir) you want to access ...
1
2010-06-24T09:29:29Z
[ "python", "django", "google-app-engine" ]
Tkinter button bind and parent deatroy
1,077,932
<p>This is my code :</p> <pre><code> print '1' from Tkinter import * print '2' class myApp: print '3' def __init__(self,parent): print '4' ## self.myparent = parent line1 print '11' self.myContainer1 = Frame(parent) print '12' self.myContainer1.pack() ...
0
2009-07-03T05:58:37Z
1,077,969
<p>Assign the incoming parameter parent to self.parent?</p> <pre><code>def __init__(self,parent): self.parent = parent </code></pre>
0
2009-07-03T06:19:03Z
[ "python", "tkinter" ]
Tkinter button bind and parent deatroy
1,077,932
<p>This is my code :</p> <pre><code> print '1' from Tkinter import * print '2' class myApp: print '3' def __init__(self,parent): print '4' ## self.myparent = parent line1 print '11' self.myContainer1 = Frame(parent) print '12' self.myContainer1.pack() ...
0
2009-07-03T05:58:37Z
1,077,987
<p>Why ever did you comment out those two lines mentioning <code>self.myparent</code> and create a new one mentioning a mysterious, never-initialized <code>self.parent</code>?! That's the start of your problem, of course -- looks like absurd, deliberate sabotage of code.</p>
2
2009-07-03T06:23:14Z
[ "python", "tkinter" ]
Tkinter button bind and parent deatroy
1,077,932
<p>This is my code :</p> <pre><code> print '1' from Tkinter import * print '2' class myApp: print '3' def __init__(self,parent): print '4' ## self.myparent = parent line1 print '11' self.myContainer1 = Frame(parent) print '12' self.myContainer1.pack() ...
0
2009-07-03T05:58:37Z
1,078,173
<p>Your question is not tkinter related, it's rather about object oriented design.</p> <p>Class <strong>myApp</strong> has <strong>__init__</strong> method (constructor, the method that executes when object of that class is created), as well as two methods for button clicks. In button2Click method, you attempt to read...
0
2009-07-03T07:25:15Z
[ "python", "tkinter" ]
Tkinter button bind and parent deatroy
1,077,932
<p>This is my code :</p> <pre><code> print '1' from Tkinter import * print '2' class myApp: print '3' def __init__(self,parent): print '4' ## self.myparent = parent line1 print '11' self.myContainer1 = Frame(parent) print '12' self.myContainer1.pack() ...
0
2009-07-03T05:58:37Z
1,078,281
<p>The other answers so far are great. <br /> This may also help: <a href="http://www.pythonware.com/library/tkinter/introduction/" rel="nofollow">Fredrik Lundh's intro to Tkinter</a>.</p> <p>Added some comments to your code that, along with the other answers, should help get you moving again: </p> <pre><code>import...
0
2009-07-03T07:58:40Z
[ "python", "tkinter" ]
Handling exceptions without try block in Python's interactive shell
1,078,054
<p>See the title of this question. I want to play with the exception raised in the last command. <code>_</code> didn't help me. Is there anything like that?</p>
2
2009-07-03T06:51:21Z
1,078,077
<p>Do this:</p> <pre><code>import sys sys.exc_info() </code></pre> <p>It will give you information about the exception. It's a tuple containing the exception type, the exception instance and a traceback object. </p>
5
2009-07-03T06:56:37Z
[ "python", "command-line", "exception-handling", "interactive-mode" ]
pymacs: General question and Installation problem
1,078,069
<p>I am trying to setup emacs for python development. </p> <p>From what I read, it is recommended to use python-mode.el rather than the default python.el from Emacs 22.3. So I embark on the new adventure.</p> <p>From what I understand, python-mode has the several dependencies, so I need to install rope, ropemode and ...
6
2009-07-03T06:55:40Z
1,078,183
<p>I have never used pymacs so far, but one thing which catches my eye when I look at your <code>.emacs</code> is that you apparently didn't add the pymacs directory to the <em>emacs</em> <code>load-path</code> but only to the <code>pymacs</code> one:</p> <pre><code>(setq pymacs-load-path '( "~/.emacs.d/site-lisp/rope...
1
2009-07-03T07:28:47Z
[ "python", "emacs", "rope", "pymacs" ]
pymacs: General question and Installation problem
1,078,069
<p>I am trying to setup emacs for python development. </p> <p>From what I read, it is recommended to use python-mode.el rather than the default python.el from Emacs 22.3. So I embark on the new adventure.</p> <p>From what I understand, python-mode has the several dependencies, so I need to install rope, ropemode and ...
6
2009-07-03T06:55:40Z
1,085,313
<p>It turns out I missed these two:</p> <pre><code>(add-to-list 'load-path "~/.emacs.d/site-lisp/Pymacs-0.23") </code></pre> <p>Obviously I need to load the pymac script.</p> <p>And I have set the env var PYMACS_PYTHON to python 2.6 because I am using python 2.4 as default python interpreter, for work reason.</p>
1
2009-07-06T03:38:31Z
[ "python", "emacs", "rope", "pymacs" ]
pymacs: General question and Installation problem
1,078,069
<p>I am trying to setup emacs for python development. </p> <p>From what I read, it is recommended to use python-mode.el rather than the default python.el from Emacs 22.3. So I embark on the new adventure.</p> <p>From what I understand, python-mode has the several dependencies, so I need to install rope, ropemode and ...
6
2009-07-03T06:55:40Z
3,430,210
<p>If paths are missing then this will easily be spotted in the startup log or by getting a backtrace at emacs start. If in doubt M-x load-library is the way to go.</p> <p>I too am getting company-ropemacs refusing to load with both emacs 23 and emacs 24 after latest Debian Testing updates which then means you can not...
1
2010-08-07T11:20:37Z
[ "python", "emacs", "rope", "pymacs" ]
Restarting a Django application running on Apache + mod_python
1,078,166
<p>I'm running a Django app on Apache + mod_python. When I make some changes to the code, sometimes they have effect immediately, other times they don't, until I restart Apache. However I don't really want to do that since it's a production server running other stuff too. Is there some other way to force that?</p> <p>...
8
2009-07-03T07:23:55Z
1,078,235
<p>Use a test server included in Django. (like <code>./manage.py runserver 0.0.0.0:8080</code>) It will do most things you would need during development. The only drawback is that it cannot handle simultaneous requests with multi-threading.</p> <p>I've heard that there is a trick that setting Apache's max instances to...
-1
2009-07-03T07:41:34Z
[ "python", "django", "mod-python" ]
Restarting a Django application running on Apache + mod_python
1,078,166
<p>I'm running a Django app on Apache + mod_python. When I make some changes to the code, sometimes they have effect immediately, other times they don't, until I restart Apache. However I don't really want to do that since it's a production server running other stuff too. Is there some other way to force that?</p> <p>...
8
2009-07-03T07:23:55Z
1,078,282
<p>If possible, you should switch to mod_wsgi. This is now the <a href="http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/">recommended way</a> to serve Django anyway, and is much more efficient in terms of memory and server resources.</p> <p>In mod_wsgi, each site has a <code>.wsgi</code> file associated ...
15
2009-07-03T07:58:49Z
[ "python", "django", "mod-python" ]
Restarting a Django application running on Apache + mod_python
1,078,166
<p>I'm running a Django app on Apache + mod_python. When I make some changes to the code, sometimes they have effect immediately, other times they don't, until I restart Apache. However I don't really want to do that since it's a production server running other stuff too. Is there some other way to force that?</p> <p>...
8
2009-07-03T07:23:55Z
1,078,289
<p>You can reduce number of connections to 1 by setting "MaxRequestsPerChild 1" in your httpd.conf file. But do it only on test server, not production.</p> <p>or </p> <p>If you don't want to kill existing connections and still restart apache you can restart it "gracefully" by performing "apache2ctl gracefully" - all ...
0
2009-07-03T08:01:27Z
[ "python", "django", "mod-python" ]
Restarting a Django application running on Apache + mod_python
1,078,166
<p>I'm running a Django app on Apache + mod_python. When I make some changes to the code, sometimes they have effect immediately, other times they don't, until I restart Apache. However I don't really want to do that since it's a production server running other stuff too. Is there some other way to force that?</p> <p>...
8
2009-07-03T07:23:55Z
1,078,713
<p>As others have suggested, use mod_wsgi instead. To get the ability for automatic reloading, through touching the WSGI script file, or through a monitor that looks for code changes, you must be using daemon mode on UNIX. A slight of hand can be used to achieve same on Windows when using embedded mode. All the details...
4
2009-07-03T10:07:07Z
[ "python", "django", "mod-python" ]
SharePoint via SOAP using Python
1,078,593
<p>I have been following the solution noted here - as this is exactly what I need to achieve;</p> <p><a href="http://stackoverflow.com/questions/218987/how-can-i-use-sharepoint-via-soap-from-python">http://stackoverflow.com/questions/218987/how-can-i-use-sharepoint-via-soap-from-python</a></p> <p>however when I run o...
0
2009-07-03T09:33:07Z
1,189,001
<p>According to <a href="https://fedorahosted.org/suds/browser/trunk/suds/client.py?rev=504" rel="nofollow">https://fedorahosted.org/suds/browser/trunk/suds/client.py?rev=504</a></p> <pre><code>434 class SoapClient: ... 445 """ 446 447 def __init__(self, client, method): 448 """ 44...
1
2009-07-27T15:57:34Z
[ "python", "sharepoint", "soap", "suds" ]
Deploying a Web.py application with WSGI, several servers
1,078,599
<p>I've created a web.py application, and now that it is ready to be deployed, I want to run in not on web.py's built-in webserver. I want to be able to run it on different webservers, Apache or IIS, without having to change my application code. This is where WSGI is supposed to come in, if I understand it correctly.<b...
6
2009-07-03T09:35:35Z
1,078,743
<p>Exactly what you need to do to host it with a specific WSGI hosting mechanism varies with the server.</p> <p>For the case of Apache/mod_wsgi and Phusion Passenger, you just need to provide a WSGI script file which contains an object called 'application'. For web.py 0.2, this is the result of calling web.wsgifunc() ...
6
2009-07-03T10:18:09Z
[ "python", "wsgi", "web.py" ]
Deploying a Web.py application with WSGI, several servers
1,078,599
<p>I've created a web.py application, and now that it is ready to be deployed, I want to run in not on web.py's built-in webserver. I want to be able to run it on different webservers, Apache or IIS, without having to change my application code. This is where WSGI is supposed to come in, if I understand it correctly.<b...
6
2009-07-03T09:35:35Z
1,245,928
<p>As of July 21 2009, there is a much fuller installation guide at <a href="http://webpy.org/install" rel="nofollow">the webpy install site</a>, that discusses <strong>flup</strong>, <strong>fastcgi</strong>, <strong>apache</strong> and more. I haven't yet <em>tried</em> it, but it seems like it's much more detailed....
0
2009-08-07T17:12:58Z
[ "python", "wsgi", "web.py" ]
Deploying a Web.py application with WSGI, several servers
1,078,599
<p>I've created a web.py application, and now that it is ready to be deployed, I want to run in not on web.py's built-in webserver. I want to be able to run it on different webservers, Apache or IIS, without having to change my application code. This is where WSGI is supposed to come in, if I understand it correctly.<b...
6
2009-07-03T09:35:35Z
1,406,572
<p>Here is an example of two hosted apps using cherrypy wsgi server:</p> <pre> #!/usr/bin/python from web import wsgiserver import web # webpy wsgi app urls = ( '/test.*', 'index' ) class index: def GET(self): web.header("content-type", "text/html") return "Hello, world1!" application = web.a...
0
2009-09-10T17:16:35Z
[ "python", "wsgi", "web.py" ]
wxPython menu doesn't display image
1,078,661
<p>I am creating a menu and assigning images to menu items, sometime first item in menu doesn't display any image, I am not able to find the reason. I have tried to make a simple stand alone example and below is the code which does demonstrates the problem on my machine. I am using windows XP, wx 2.8.7.1 (msw-unicode)'...
3
2009-07-03T09:51:59Z
1,078,810
<p>This is a <a href="http://trac.wxwidgets.org/ticket/4011" rel="nofollow">confirmed bug</a> which appearently has been open for quite a while. After trying around a little bit, this workaround seems to do it:</p> <pre><code> menuBar = wx.MenuBar() fileMenu=wx.Menu() tempitem = fileMenu.Append(-1,"X") ...
2
2009-07-03T10:44:28Z
[ "python", "menu", "wxpython" ]
wxPython menu doesn't display image
1,078,661
<p>I am creating a menu and assigning images to menu items, sometime first item in menu doesn't display any image, I am not able to find the reason. I have tried to make a simple stand alone example and below is the code which does demonstrates the problem on my machine. I am using windows XP, wx 2.8.7.1 (msw-unicode)'...
3
2009-07-03T09:51:59Z
1,225,117
<p>This hack does not appear to be necessary if you create each menu item with wx.MenuItem(), set its bitmap, and only then append it to the menu. This causes the bitmaps to show up correctly. I'm testing with wxPython 2.8.10.1 on Windows.</p>
4
2009-08-03T23:35:16Z
[ "python", "menu", "wxpython" ]
Advanced SAX Parser in C#
1,078,902
<p>See Below is the XML Arch. I want to display it in row / column wize.</p> <p>What I need is I need to convert this xml file to Hashtable like,</p> <pre><code>{"form" : {"attrs" : { "string" : " Partners" } {"child1": { "group" : { "attrs" : { "col" : "6", "colspan":"1" } } ...
1
2009-07-03T11:16:22Z
1,116,506
<blockquote> <p>from xml.sax.handler import ContentHandler import xml class my_handler(ContentHandler):</p> <pre><code>def get_attr_dict(self, attrs): ret_dict = {} for name in attrs.getNames(): ret_dict[name] = attrs.getValue(name) #end for name in attrs.getNames(): return ret_dict def ...
0
2009-07-12T17:43:07Z
[ ".net", "python", "xml", "parsing", "sax" ]
I'd like to call the Windows C++ function WinHttpGetProxyForUrl from Python - can this be done?
1,078,939
<p>Microsoft provides a method as part of WinHTTP which allows a user to determine which Proxy ought to be used for any given URL. It's called <a href="http://msdn.microsoft.com/en-us/library/aa384097%28VS.85%29.aspx" rel="nofollow">WinHttpGetProxyForUrl</a>.</p> <p>Unfortunately I'm programming in python so I cannot ...
1
2009-07-03T11:25:08Z
1,079,007
<p>You can use ctypes to call function in WinHttp.dll, it is the DLL which contains 'WinHttpGetProxyForUrl. ' Though to call it you will need a HINTERNET session variable, so here I am showing you the first step, it shows how you can use ctypes to call into DLL,it produces a HINTERNET which you have to pass to WinHttpG...
1
2009-07-03T11:47:10Z
[ "c++", "python", "windows", "com" ]
I'd like to call the Windows C++ function WinHttpGetProxyForUrl from Python - can this be done?
1,078,939
<p>Microsoft provides a method as part of WinHTTP which allows a user to determine which Proxy ought to be used for any given URL. It's called <a href="http://msdn.microsoft.com/en-us/library/aa384097%28VS.85%29.aspx" rel="nofollow">WinHttpGetProxyForUrl</a>.</p> <p>Unfortunately I'm programming in python so I cannot ...
1
2009-07-03T11:25:08Z
1,079,010
<p>This page at ActiveState: <a href="http://docs.activestate.com/activepython/2.5/pywin32/WINHTTP%5FAUTOPROXY%5FOPTIONS.html" rel="nofollow"><code>WINHTTP_AUTOPROXY_OPTIONS</code> Object</a> implies that <code>WinHttpGetProxyForUrl</code> is available in the win32inet module of the Win32 extensions. SourceForge is cu...
1
2009-07-03T11:47:47Z
[ "c++", "python", "windows", "com" ]
How to put Google login box inside flash in GAE?
1,079,022
<p>I am putting my old flash site into GAE. I want to use Google's user authentication too. Now, I want to put Googles login box inside the flash instead of redirecting to Google's login page. Same thing I want for forgot password.</p> <p>Is it possible to do this? How to do this?</p>
0
2009-07-03T11:50:41Z
1,353,761
<p>Of course this is possible you just need to use flash to post http request to your server and your server could communicate to flash through several ways like: xml , html, and AMF or even johnson( I am not sure).</p> <p>I recommend you use pyamf at server side to build a native support for flash at server side</p>
1
2009-08-30T12:15:11Z
[ "python", "flash", "google-app-engine", "authentication" ]
How to emulate language complement operator in .hgignore?
1,079,342
<p>I have a Python regular expression that matches a set of filenames. How to change it so that I can use it in Mercurial's .hgignore file to ignore files that do <em>not</em> match the expression?</p> <p>Full story: I have a big source tree with <code>*.ml</code> files scattered everywhere. I want to put them into a ...
3
2009-07-03T13:22:55Z
1,079,968
<p>Through some testing, found two solutions that appear to work. The first roots to a subdirectory, and apparently this is significant. The second is brittle, because it only allows one suffix to be used. I'm running these tests on Windows XP (customized to work a bit more unixy) with Mercurial 1.2.1.</p> <p>(Comm...
0
2009-07-03T16:02:23Z
[ "python", "regex", "mercurial" ]
How to emulate language complement operator in .hgignore?
1,079,342
<p>I have a Python regular expression that matches a set of filenames. How to change it so that I can use it in Mercurial's .hgignore file to ignore files that do <em>not</em> match the expression?</p> <p>Full story: I have a big source tree with <code>*.ml</code> files scattered everywhere. I want to put them into a ...
3
2009-07-03T13:22:55Z
1,080,058
<p>The problem appears specifically to be that matches in subdirectories are different to the root. Note the following:</p> <pre><code>$ hg --version Mercurial Distributed SCM (version 1.1.2) </code></pre> <p>It's an older version, but it behaves in the same way. My project has the following files:</p> <pre><code>$ ...
0
2009-07-03T16:32:28Z
[ "python", "regex", "mercurial" ]
How to emulate language complement operator in .hgignore?
1,079,342
<p>I have a Python regular expression that matches a set of filenames. How to change it so that I can use it in Mercurial's .hgignore file to ignore files that do <em>not</em> match the expression?</p> <p>Full story: I have a big source tree with <code>*.ml</code> files scattered everywhere. I want to put them into a ...
3
2009-07-03T13:22:55Z
1,080,439
<p>The regexs are applied to each subdirectory component in turn as well as the file name, not the entire relative path at once. So if I have a/b/c/d in my repo, each regex will be applied to a, a/b, a/b/c as well as a/b/c/d. If any component matches, the file will be ignored. (You can tell that this is the behaviour b...
1
2009-07-03T18:41:12Z
[ "python", "regex", "mercurial" ]
Sphinx templating
1,079,417
<p>I am using <a href="http://sphinx.pocoo.org" rel="nofollow">sphinx</a>. I want to template it. So after reading the docs, what I am trying is, in my conf.py,</p> <p>I put a line like, </p> <pre><code>templates_path = ['_templates'] </code></pre> <p>and I created a file </p> <pre><code>_templates/page.html </code...
6
2009-07-03T13:42:37Z
1,079,474
<p>The documentation <a href="http://sphinx.pocoo.org/templating.html#working-the-the-builtin-templates" rel="nofollow">http://sphinx.pocoo.org/templating.html#working-the-the-builtin-templates</a> says that the template it's looking for is <code>layout.html</code>.</p> <p>Perhaps you should use that name.</p>
1
2009-07-03T13:55:31Z
[ "python", "documentation", "python-sphinx" ]
Sphinx templating
1,079,417
<p>I am using <a href="http://sphinx.pocoo.org" rel="nofollow">sphinx</a>. I want to template it. So after reading the docs, what I am trying is, in my conf.py,</p> <p>I put a line like, </p> <pre><code>templates_path = ['_templates'] </code></pre> <p>and I created a file </p> <pre><code>_templates/page.html </code...
6
2009-07-03T13:42:37Z
1,112,717
<p>This works for me. Perhaps you need to force a rebuild for all files with the command <code>sphinx-build -a</code>? Sphinx only compiles HTML files that it detects as having changed. Another option is to just touch all your source files with <code>touch *.rst</code>.</p>
0
2009-07-11T01:53:19Z
[ "python", "documentation", "python-sphinx" ]
Sphinx templating
1,079,417
<p>I am using <a href="http://sphinx.pocoo.org" rel="nofollow">sphinx</a>. I want to template it. So after reading the docs, what I am trying is, in my conf.py,</p> <p>I put a line like, </p> <pre><code>templates_path = ['_templates'] </code></pre> <p>and I created a file </p> <pre><code>_templates/page.html </code...
6
2009-07-03T13:42:37Z
1,767,202
<p>Be sure you are using the theme name as an explicit directory in your template. e.g.: </p> <p><code>{% extends "basic/layout.html" %}</code></p> <p>see: <a href="http://sphinx.pocoo.org/theming.html#templating">HTML Theming Support</a></p>
5
2009-11-19T23:06:00Z
[ "python", "documentation", "python-sphinx" ]
What's the correct way to use win32inet.WinHttpGetProxyForUrl
1,079,655
<p>I'm trying to use a feature of the Microsoft WinHttp library that has been exposed by the developers of Win32com. Unfortunately most of the library does not seem to be documented and there are no example of the correct way to use the win32inet features via the win32com library.</p> <p>This is what I have so far:</p...
3
2009-07-03T14:41:10Z
1,092,465
<p>Unless there is a strong reason for using <code>win32inet</code> (which is messy in this area due to limitations of <code>SWIG</code>), I recommend that you use <code>ctypes</code> instead.</p>
1
2009-07-07T13:50:57Z
[ "python", "windows", "com", "32-bit", "winhttp" ]
What's the correct way to use win32inet.WinHttpGetProxyForUrl
1,079,655
<p>I'm trying to use a feature of the Microsoft WinHttp library that has been exposed by the developers of Win32com. Unfortunately most of the library does not seem to be documented and there are no example of the correct way to use the win32inet features via the win32com library.</p> <p>This is what I have so far:</p...
3
2009-07-03T14:41:10Z
1,096,346
<p>Here is the code which creates HINTERNET session and uses that to get proxy details, using ctypes to directly access winhttp DLL. It works without any error but I have no proxy set on my machine, you may have to tweak few constants to get it right. Go thru the msdn links in code, from where I have seen the API.</p> ...
6
2009-07-08T06:09:28Z
[ "python", "windows", "com", "32-bit", "winhttp" ]
What's the correct way to use win32inet.WinHttpGetProxyForUrl
1,079,655
<p>I'm trying to use a feature of the Microsoft WinHttp library that has been exposed by the developers of Win32com. Unfortunately most of the library does not seem to be documented and there are no example of the correct way to use the win32inet features via the win32com library.</p> <p>This is what I have so far:</p...
3
2009-07-03T14:41:10Z
21,117,496
<p>At least with <code>Python 2.7.6</code> and <code>Pywin 218</code> on Windows XP x86 and Windows 8 x64, it works:</p> <pre><code>import win32inet # http://msdn.microsoft.com/en-us/library/windows/desktop/aa384098(v=vs.85).aspx hinternet = win32inet.WinHttpOpen("foo", 0, "", "", 0) # http://msdn.microsoft.com/en-us...
1
2014-01-14T15:37:42Z
[ "python", "windows", "com", "32-bit", "winhttp" ]
Preventing invoking C types from Python
1,079,690
<p>What's the correct way to prevent invoking (creating an instance of) a C type from Python?</p> <p>I've considered providing a <code>tp_init</code> that raises an exception, but as I understand it that would still allow <code>__new__</code> to be called directly on the type.</p> <p>A C function returns instances of...
2
2009-07-03T14:49:31Z
1,079,881
<p>Don't prevent them from doing it. "<a href="http://mail.python.org/pipermail/tutor/2003-October/025932.html" rel="nofollow">We're all consenting adults here</a>."</p> <p>Nobody is going to do it unless they have a reason, and if they have such a reason then you shouldn't stop them just because you didn't anticipate...
1
2009-07-03T15:36:27Z
[ "python", "cpython" ]
Preventing invoking C types from Python
1,079,690
<p>What's the correct way to prevent invoking (creating an instance of) a C type from Python?</p> <p>I've considered providing a <code>tp_init</code> that raises an exception, but as I understand it that would still allow <code>__new__</code> to be called directly on the type.</p> <p>A C function returns instances of...
2
2009-07-03T14:49:31Z
1,079,981
<p>"The type is a return type of another C function - that's the only way instances of this type are intended to be created" -- that's rather confusing. I think you mean "A C function returns instances of this type -- that's the only way etc etc".</p> <p>In your documentation, warn the caller clearly against invoking ...
0
2009-07-03T16:05:32Z
[ "python", "cpython" ]
Preventing invoking C types from Python
1,079,690
<p>What's the correct way to prevent invoking (creating an instance of) a C type from Python?</p> <p>I've considered providing a <code>tp_init</code> that raises an exception, but as I understand it that would still allow <code>__new__</code> to be called directly on the type.</p> <p>A C function returns instances of...
2
2009-07-03T14:49:31Z
1,080,330
<p>There is a fantastically bulletproof way. Let people create the object, and have Python crash. That should stop them doing it pretty efficiently. ;)</p> <p>Also you can underscore the class name, to indicate that it should be internal. (At least, I assume you can create underscored classnames from C too, I haven't...
0
2009-07-03T17:58:57Z
[ "python", "cpython" ]
Preventing invoking C types from Python
1,079,690
<p>What's the correct way to prevent invoking (creating an instance of) a C type from Python?</p> <p>I've considered providing a <code>tp_init</code> that raises an exception, but as I understand it that would still allow <code>__new__</code> to be called directly on the type.</p> <p>A C function returns instances of...
2
2009-07-03T14:49:31Z
1,080,514
<p>Simple: leave the tp_new slot of the type empty.</p> <pre><code>&gt;&gt;&gt; Foo() Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: cannot create 'foo.Foo' instances &gt;&gt;&gt; Foo.__new__(Foo) Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt...
3
2009-07-03T19:12:16Z
[ "python", "cpython" ]
How do you extract a JAR in a UNIX filesystem with a single command and specify its target directory using the JAR command?
1,079,693
<p>I am creating a Python script within which I am executing UNIX system commands. I have a war archive named Binaries.war which is within an ear archive named Portal.ear</p> <p>The Portal ear file resides in, say /home/foo/bar/</p> <pre><code>jar xf /home/foo/bar/Portal.ear Binaries.war </code></pre> <p>Will extrac...
36
2009-07-03T14:50:06Z
1,079,726
<p>I don't think the jar tool supports this natively, but you can just unzip a JAR file with "unzip" and specify the output directory with that with the "-d" option, so something like:</p> <pre><code>$ unzip -d /home/foo/bar/baz /home/foo/bar/Portal.ear Binaries.war </code></pre>
47
2009-07-03T14:56:40Z
[ "java", "python", "linux", "unix", "jar" ]
How do you extract a JAR in a UNIX filesystem with a single command and specify its target directory using the JAR command?
1,079,693
<p>I am creating a Python script within which I am executing UNIX system commands. I have a war archive named Binaries.war which is within an ear archive named Portal.ear</p> <p>The Portal ear file resides in, say /home/foo/bar/</p> <pre><code>jar xf /home/foo/bar/Portal.ear Binaries.war </code></pre> <p>Will extrac...
36
2009-07-03T14:50:06Z
1,079,733
<p>Can't you just change working directory within the python script using <a href="http://docs.python.org/library/os.html" rel="nofollow"><code>os.chdir(target)</code></a>? I agree, I can't see any way of doing it from the jar command itself.</p> <p>If you don't want to permanently change directory, then store the cur...
1
2009-07-03T14:57:56Z
[ "java", "python", "linux", "unix", "jar" ]
How do you extract a JAR in a UNIX filesystem with a single command and specify its target directory using the JAR command?
1,079,693
<p>I am creating a Python script within which I am executing UNIX system commands. I have a war archive named Binaries.war which is within an ear archive named Portal.ear</p> <p>The Portal ear file resides in, say /home/foo/bar/</p> <pre><code>jar xf /home/foo/bar/Portal.ear Binaries.war </code></pre> <p>Will extrac...
36
2009-07-03T14:50:06Z
1,079,803
<p>If your jar file already has an absolute pathname as shown, it is particularly easy:</p> <pre><code>cd /where/you/want/it; jar xf /path/to/jarfile.jar </code></pre> <p>That is, you have the shell executed by Python change directory for you and then run the extraction.</p> <p>If your jar file does not already have...
48
2009-07-03T15:12:40Z
[ "java", "python", "linux", "unix", "jar" ]
How do you extract a JAR in a UNIX filesystem with a single command and specify its target directory using the JAR command?
1,079,693
<p>I am creating a Python script within which I am executing UNIX system commands. I have a war archive named Binaries.war which is within an ear archive named Portal.ear</p> <p>The Portal ear file resides in, say /home/foo/bar/</p> <pre><code>jar xf /home/foo/bar/Portal.ear Binaries.war </code></pre> <p>Will extrac...
36
2009-07-03T14:50:06Z
1,121,899
<p>If this is a personal script, rather than one you're planning on distributing, it might be simpler to write a shell function for this:</p> <pre><code>function warextract { jar xf $1 $2 &amp;&amp; mv $2 $3 } </code></pre> <p>which you could then call from python like so:</p> <pre><code>warextract /home/foo/bar/Por...
1
2009-07-13T20:39:49Z
[ "java", "python", "linux", "unix", "jar" ]