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
GIS: When and why to use ArcObjects over GDAL programming to work with ArcGIS rasters and vectors?
2,276,235
<p>Im just starting off with GDAL + python to support operations that cannot be done with ArcGIS python geoprocessing scripting. Mainly I am doing spatial modeling/analysis/editing of raster and vector data.</p> <p>I am a bit confused when ArcObject development is required versus when GDAL can be used? Is there functi...
3
2010-02-16T20:50:30Z
2,808,353
<p>geographika's answer is superb. I'll only add that I use gdal/ogr when simplicity and speed is wanted in conversions. Examples include one format to another, adding image pyramids, simple merging and coordinate transformation (raster &amp; vector). When all you want to do is jam a bunch of shapefiles together or con...
4
2010-05-11T05:49:51Z
[ "python", "gis", "arcgis", "gdal" ]
IF in the Django template system
2,276,319
<p>How do I do this:</p> <pre><code>{% if thestring %} {% if thestring.find("1") &gt;= 0 %} {% endif %} {% endif %} </code></pre> <p>I am assuming I need to build a template filter? Will that work?</p>
0
2010-02-16T21:02:43Z
2,276,336
<p>It would. But use the <code>in</code> operator instead of the <code>find()</code> method.</p> <p>Example:</p> <pre><code>{% if thestring|contains:"1" %} </code></pre>
3
2010-02-16T21:06:07Z
[ "python", "django", "templates" ]
IF in the Django template system
2,276,319
<p>How do I do this:</p> <pre><code>{% if thestring %} {% if thestring.find("1") &gt;= 0 %} {% endif %} {% endif %} </code></pre> <p>I am assuming I need to build a template filter? Will that work?</p>
0
2010-02-16T21:02:43Z
2,276,345
<p>I believe you'll find that the Django template system isn't designed to have complex logic in it. This type of processing should happen in your view, then be passed to the template.</p>
1
2010-02-16T21:06:57Z
[ "python", "django", "templates" ]
IF in the Django template system
2,276,319
<p>How do I do this:</p> <pre><code>{% if thestring %} {% if thestring.find("1") &gt;= 0 %} {% endif %} {% endif %} </code></pre> <p>I am assuming I need to build a template filter? Will that work?</p>
0
2010-02-16T21:02:43Z
2,276,354
<p>You don't <em>need</em> to build a custom filter, though one would work -- the alternative of coding</p> <pre><code>{% if thestring %} {% if "1" in thestring %} {% endif %} {% endif %} </code></pre> <p>would also go just fine.</p>
3
2010-02-16T21:08:39Z
[ "python", "django", "templates" ]
PyScripter Rpyc
2,276,323
<p>maybe somebody could give me a couple guidelines how to install Rpyc to PyScripter. I use PyScripter 1.9.9.7 with Python 2.6. I have tried to google it and found some instructions, but still have not succeeded...</p> <p>Thanks!</p>
4
2010-02-16T21:03:44Z
2,279,988
<p>Grab the file <strong>rpyc-2.60-py24.zip</strong> from here:</p> <p><a href="http://code.google.com/p/pyscripter/downloads/list" rel="nofollow">http://code.google.com/p/pyscripter/downloads/list</a></p> <p>Under your python2.6 install directory go to the following subdirectory</p> <p>\Lib\site-packages\</p> <p>c...
4
2010-02-17T10:51:21Z
[ "python", "pyscripter", "rpyc" ]
Extending a list of lists in Python?
2,276,416
<p>I might be missing something about the intended behavior of list extend, but why does the following happen?</p> <pre><code>x = [[],[]] y = [[]] * 2 print x # [[],[]] print y # [[],[]] print x == y # True x[0].extend([1]) y[0].extend([1]) print x # [[1],[]], which is what I'd expect print y # [...
8
2010-02-16T21:18:16Z
2,276,437
<p>The statement <code>y = [[]] * 2</code> binds <code>y</code> to a list containing 2 copies of the same list. Use:</p> <pre><code>y = [[], []] </code></pre> <p>or</p> <pre><code>y = [[] for n in range(2)] </code></pre>
4
2010-02-16T21:20:19Z
[ "python", "list", "extend" ]
Extending a list of lists in Python?
2,276,416
<p>I might be missing something about the intended behavior of list extend, but why does the following happen?</p> <pre><code>x = [[],[]] y = [[]] * 2 print x # [[],[]] print y # [[],[]] print x == y # True x[0].extend([1]) y[0].extend([1]) print x # [[1],[]], which is what I'd expect print y # [...
8
2010-02-16T21:18:16Z
2,276,439
<p><code>y</code> contains two references to a single, mutable, list.</p>
1
2010-02-16T21:20:42Z
[ "python", "list", "extend" ]
Extending a list of lists in Python?
2,276,416
<p>I might be missing something about the intended behavior of list extend, but why does the following happen?</p> <pre><code>x = [[],[]] y = [[]] * 2 print x # [[],[]] print y # [[],[]] print x == y # True x[0].extend([1]) y[0].extend([1]) print x # [[1],[]], which is what I'd expect print y # [...
8
2010-02-16T21:18:16Z
2,276,443
<p>In the case of <code>[something] * 2</code>, python is simply making a reference-copy. Therefore, if the enclosed type(s) are mutable, changing them will be reflected anywhere the item is referenced.</p> <p>In your example, <code>y[0]</code> and <code>y[1]</code> point to the same enclosed list object. You can veri...
13
2010-02-16T21:21:22Z
[ "python", "list", "extend" ]
Path of current Python instance?
2,276,512
<p>I need to access the <code>Scripts</code> and <code>tcl</code> sub-directories of the currently executing Python instance's installation directory on Windows.</p> <p>What is the best way to locate these directories?</p>
1
2010-02-16T21:31:29Z
2,276,543
<p>Hmm, find the Lib dir from sys.path and extrapolate from there?</p>
0
2010-02-16T21:37:16Z
[ "python", "windows", "installation", "path", "python-3.x" ]
Path of current Python instance?
2,276,512
<p>I need to access the <code>Scripts</code> and <code>tcl</code> sub-directories of the currently executing Python instance's installation directory on Windows.</p> <p>What is the best way to locate these directories?</p>
1
2010-02-16T21:31:29Z
2,276,557
<p>Have a look at <code>sys.prefix</code> and <code>sys.exec_prefix</code></p> <pre><code>&gt;&gt;&gt; import sys &gt;&gt;&gt; sys.prefix '/System/Library/Frameworks/Python.framework/Versions/2.6' &gt;&gt;&gt; sys.exec_prefix '/System/Library/Frameworks/Python.framework/Versions/2.6' </code></pre>
3
2010-02-16T21:39:41Z
[ "python", "windows", "installation", "path", "python-3.x" ]
How do I unit test a module that relies on urllib2?
2,276,689
<p>I've got a piece of code that I can't figure out how to unit test! The module pulls content from external XML feeds (twitter, flickr, youtube, etc.) with urllib2. Here's some pseudo-code for it:</p> <pre><code>params = (url, urlencode(data),) if data else (url,) req = Request(*params) response = urlopen(req) #check...
20
2010-02-16T22:02:16Z
2,276,727
<p>It would be best if you could write a mock urlopen (and possibly Request) which provides the minimum required interface to behave like urllib2's version. You'd then need to have your function/method which uses it able to accept this mock urlopen somehow, and use <code>urllib2.urlopen</code> otherwise.</p> <p>This i...
8
2010-02-16T22:08:52Z
[ "python", "unit-testing", "urllib2", "urllib" ]
How do I unit test a module that relies on urllib2?
2,276,689
<p>I've got a piece of code that I can't figure out how to unit test! The module pulls content from external XML feeds (twitter, flickr, youtube, etc.) with urllib2. Here's some pseudo-code for it:</p> <pre><code>params = (url, urlencode(data),) if data else (url,) req = Request(*params) response = urlopen(req) #check...
20
2010-02-16T22:02:16Z
2,276,732
<p>Build a separate class or module responsible for communicating with your external feeds.</p> <p>Make this class able to be a <a href="http://www.martinfowler.com/bliki/TestDouble.html" rel="nofollow">test double</a>. You're using python, so you're pretty golden there; if you were using C#, I'd suggest either in int...
5
2010-02-16T22:09:20Z
[ "python", "unit-testing", "urllib2", "urllib" ]
How do I unit test a module that relies on urllib2?
2,276,689
<p>I've got a piece of code that I can't figure out how to unit test! The module pulls content from external XML feeds (twitter, flickr, youtube, etc.) with urllib2. Here's some pseudo-code for it:</p> <pre><code>params = (url, urlencode(data),) if data else (url,) req = Request(*params) response = urlopen(req) #check...
20
2010-02-16T22:02:16Z
2,276,849
<p>I think the easiest thing to do is to actually create a simple web server in your unit test. When you start the test, create a new thread that listens on some arbitrary port and when a client connects just returns a known set of headers and XML, then terminates.</p> <p>I can elaborate if you need more info.</p> <p...
1
2010-02-16T22:24:32Z
[ "python", "unit-testing", "urllib2", "urllib" ]
How do I unit test a module that relies on urllib2?
2,276,689
<p>I've got a piece of code that I can't figure out how to unit test! The module pulls content from external XML feeds (twitter, flickr, youtube, etc.) with urllib2. Here's some pseudo-code for it:</p> <pre><code>params = (url, urlencode(data),) if data else (url,) req = Request(*params) response = urlopen(req) #check...
20
2010-02-16T22:02:16Z
2,276,884
<p>urllib2 has a functions called <code>build_opener()</code> and <code>install_opener()</code> which you should use to mock the behaviour of <code>urlopen()</code></p> <pre><code>import urllib2 from StringIO import StringIO def mock_response(req): if req.get_full_url() == "http://example.com": resp = url...
23
2010-02-16T22:30:06Z
[ "python", "unit-testing", "urllib2", "urllib" ]
How do I unit test a module that relies on urllib2?
2,276,689
<p>I've got a piece of code that I can't figure out how to unit test! The module pulls content from external XML feeds (twitter, flickr, youtube, etc.) with urllib2. Here's some pseudo-code for it:</p> <pre><code>params = (url, urlencode(data),) if data else (url,) req = Request(*params) response = urlopen(req) #check...
20
2010-02-16T22:02:16Z
2,276,911
<p>Why not just <a href="http://docs.python.org/library/basehttpserver.html" rel="nofollow">mock a website</a> that returns the response you expect? then start the server in a thread in setup and kill it in the teardown. I ended up doing this for testing code that would send email by mocking an smtp server and it works...
0
2010-02-16T22:33:46Z
[ "python", "unit-testing", "urllib2", "urllib" ]
How do I unit test a module that relies on urllib2?
2,276,689
<p>I've got a piece of code that I can't figure out how to unit test! The module pulls content from external XML feeds (twitter, flickr, youtube, etc.) with urllib2. Here's some pseudo-code for it:</p> <pre><code>params = (url, urlencode(data),) if data else (url,) req = Request(*params) response = urlopen(req) #check...
20
2010-02-16T22:02:16Z
2,276,937
<p>You can use <a href="http://code.google.com/p/pymox/">pymox</a> to mock the behavior of anything and everything in the urllib2 (or any other) package. It's 2010, you shouldn't be writing your own mock classes.</p>
5
2010-02-16T22:38:02Z
[ "python", "unit-testing", "urllib2", "urllib" ]
Django, query filtering from model method
2,276,768
<p>I have these models:</p> <pre><code>def Foo(Models.model): size = models.IntegerField() # other fields def is_active(self): if check_condition: return True else: return False def Bar(Models.model): foo = models.ForeignKey("Foo") # other fields </...
47
2010-02-16T22:14:24Z
2,276,826
<p>You cannot query against model methods or properties. Either use the criteria within it in the query, or filter in Python using a list comprehension or genex.</p>
19
2010-02-16T22:22:03Z
[ "python", "django", "django-models", "django-queryset", "django-orm" ]
Django, query filtering from model method
2,276,768
<p>I have these models:</p> <pre><code>def Foo(Models.model): size = models.IntegerField() # other fields def is_active(self): if check_condition: return True else: return False def Bar(Models.model): foo = models.ForeignKey("Foo") # other fields </...
47
2010-02-16T22:14:24Z
2,276,848
<p>You can't filter on methods, however if the is_active method on Foo checks an attribute on Foo, you can use the double-underscore syntax like <code>Bar.objects.filter(foo__is_active_attribute=True)</code></p>
9
2010-02-16T22:24:29Z
[ "python", "django", "django-models", "django-queryset", "django-orm" ]
Django, query filtering from model method
2,276,768
<p>I have these models:</p> <pre><code>def Foo(Models.model): size = models.IntegerField() # other fields def is_active(self): if check_condition: return True else: return False def Bar(Models.model): foo = models.ForeignKey("Foo") # other fields </...
47
2010-02-16T22:14:24Z
15,224,757
<p>I had similar problem: I am using class-based view <code>object_list</code> and I had to filter by model's method. (storing the information in database wasn't an option because the property was based on time and I would have to create a cronjob and/or... <em>no way</em>)</p> <p>My answer is ineffective and I don't ...
8
2013-03-05T13:15:20Z
[ "python", "django", "django-models", "django-queryset", "django-orm" ]
Django, query filtering from model method
2,276,768
<p>I have these models:</p> <pre><code>def Foo(Models.model): size = models.IntegerField() # other fields def is_active(self): if check_condition: return True else: return False def Bar(Models.model): foo = models.ForeignKey("Foo") # other fields </...
47
2010-02-16T22:14:24Z
21,363,053
<p>You could also use a custom manager. Then you could run something like this:</p> <pre><code>Bar.objects.foo_active() </code></pre> <p>And all you have to do is:</p> <pre><code>class BarManager(models.Manager): def foo_active(self): # use your method to filter results return you_custom_queryset <...
17
2014-01-26T12:00:32Z
[ "python", "django", "django-models", "django-queryset", "django-orm" ]
Django, query filtering from model method
2,276,768
<p>I have these models:</p> <pre><code>def Foo(Models.model): size = models.IntegerField() # other fields def is_active(self): if check_condition: return True else: return False def Bar(Models.model): foo = models.ForeignKey("Foo") # other fields </...
47
2010-02-16T22:14:24Z
36,808,735
<pre><code>class Page(models.Model): category = models.ForeignKey(Category) title = models.CharField(max_length=128) url = models.URLField() ... class Category(models.Model): ... open = models.BooleanField(default=True) </code></pre> <p>May be you can use simple filter, for this type of conditions...
0
2016-04-23T09:00:02Z
[ "python", "django", "django-models", "django-queryset", "django-orm" ]
Automatic transformation from getter/setter to properties
2,276,800
<p>I have a big libray written in C++ and someone created an interface to use it in python (2.6) in an automatic way. Now I have a lot of classes with getter and setter methods. Really: I hate them.</p> <p>I want to reimplement the classes with a more pythonic interface using properties. The problem is that every clas...
2
2010-02-16T22:18:48Z
2,276,889
<p>Use a <a href="http://www.ibm.com/developerworks/linux/library/l-pymeta.html" rel="nofollow">metaclass</a> that looks for all attributes like <code>Get*</code> and <code>Set*</code> and adds appropriate properties to the class. Have a class attribute that you can set to a sequence containing properties that will be ...
2
2010-02-16T22:30:25Z
[ "python", "properties", "metaprogramming", "automatic-properties" ]
Automatic transformation from getter/setter to properties
2,276,800
<p>I have a big libray written in C++ and someone created an interface to use it in python (2.6) in an automatic way. Now I have a lot of classes with getter and setter methods. Really: I hate them.</p> <p>I want to reimplement the classes with a more pythonic interface using properties. The problem is that every clas...
2
2010-02-16T22:18:48Z
2,277,059
<p>Here's a way to do it with a class decorator</p> <pre><code>def make_properties(c): from collections import defaultdict props=defaultdict(dict) for k,v in vars(c).items(): if k.startswith("Get"): props[k[3:]]['getter']=v if k.startswith("Set"): props[k[3:]]['sette...
5
2010-02-16T23:03:00Z
[ "python", "properties", "metaprogramming", "automatic-properties" ]
Automatic transformation from getter/setter to properties
2,276,800
<p>I have a big libray written in C++ and someone created an interface to use it in python (2.6) in an automatic way. Now I have a lot of classes with getter and setter methods. Really: I hate them.</p> <p>I want to reimplement the classes with a more pythonic interface using properties. The problem is that every clas...
2
2010-02-16T22:18:48Z
2,277,257
<p>Be careful using magic, especially magically altering other people's bindings. This has the disadvantages that </p> <ul> <li>Your code is incompatible with other people accessing the same library. Someone can't import one of your modules or copy and paste your code and have it work perfectly with their program acce...
1
2010-02-16T23:42:14Z
[ "python", "properties", "metaprogramming", "automatic-properties" ]
Automatic transformation from getter/setter to properties
2,276,800
<p>I have a big libray written in C++ and someone created an interface to use it in python (2.6) in an automatic way. Now I have a lot of classes with getter and setter methods. Really: I hate them.</p> <p>I want to reimplement the classes with a more pythonic interface using properties. The problem is that every clas...
2
2010-02-16T22:18:48Z
19,228,688
<pre><code>class BaseObj: test = None def __init__(self, attributes_dict): self.attributes_dict = attributes_dict self.define_getters(attributes_dict.keys()) def define_getters(self, attributes_names): for attribute_name in attributes_names: setattr(self, "get_"+attribute...
1
2013-10-07T15:26:13Z
[ "python", "properties", "metaprogramming", "automatic-properties" ]
Python: Separating an HTML snippets to paragraphs
2,276,824
<p>I have a snippet of HTML that contains paragraphs. (I mean <code>p</code> tags.) I want to split the string into the different paragraphs. For instance:</p> <pre><code>''' &lt;p class="my_class"&gt;Hello!&lt;/p&gt; &lt;p&gt;What's up?&lt;/p&gt; &lt;p style="whatever: whatever;"&gt;Goodbye!&lt;/p&gt; ''' </code></pr...
3
2010-02-16T22:21:56Z
2,276,870
<p>Use <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a> to parse the HTML and iterate over the paragraphs.</p>
0
2010-02-16T22:27:27Z
[ "python", "html", "beautifulsoup", "lxml" ]
Python: Separating an HTML snippets to paragraphs
2,276,824
<p>I have a snippet of HTML that contains paragraphs. (I mean <code>p</code> tags.) I want to split the string into the different paragraphs. For instance:</p> <pre><code>''' &lt;p class="my_class"&gt;Hello!&lt;/p&gt; &lt;p&gt;What's up?&lt;/p&gt; &lt;p style="whatever: whatever;"&gt;Goodbye!&lt;/p&gt; ''' </code></pr...
3
2010-02-16T22:21:56Z
2,276,871
<p>The xml.etree (std lib) or lxml.etree (enhanced) make this easy to do, but I'm not going to get the answer cred for this because I don't remember the exact syntax. I keep mixing it up with similar packages and have to look it up afresh every time.</p>
0
2010-02-16T22:27:54Z
[ "python", "html", "beautifulsoup", "lxml" ]
Python: Separating an HTML snippets to paragraphs
2,276,824
<p>I have a snippet of HTML that contains paragraphs. (I mean <code>p</code> tags.) I want to split the string into the different paragraphs. For instance:</p> <pre><code>''' &lt;p class="my_class"&gt;Hello!&lt;/p&gt; &lt;p&gt;What's up?&lt;/p&gt; &lt;p style="whatever: whatever;"&gt;Goodbye!&lt;/p&gt; ''' </code></pr...
3
2010-02-16T22:21:56Z
2,276,875
<p>If your string only contains paragraphs, you may be able to get away with a nicely crafted regex and <code>re.split()</code>. However, if your string is more complex HTML, or not always valid HTML, you might want to look at the <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a>...
5
2010-02-16T22:28:27Z
[ "python", "html", "beautifulsoup", "lxml" ]
Python: Separating an HTML snippets to paragraphs
2,276,824
<p>I have a snippet of HTML that contains paragraphs. (I mean <code>p</code> tags.) I want to split the string into the different paragraphs. For instance:</p> <pre><code>''' &lt;p class="my_class"&gt;Hello!&lt;/p&gt; &lt;p&gt;What's up?&lt;/p&gt; &lt;p style="whatever: whatever;"&gt;Goodbye!&lt;/p&gt; ''' </code></pr...
3
2010-02-16T22:21:56Z
2,276,906
<p>Use <code>lxml.html</code> to parse the HTML into the form you want. This is essentially the same advice as the people who are recommending BeautifulSoup, except <code>lxml</code> is still being actively developed and BeatifulSoup development has slowed. </p>
2
2010-02-16T22:33:20Z
[ "python", "html", "beautifulsoup", "lxml" ]
Wrapping a pure virtual method with arguments using Boost::Python
2,277,018
<p>I'm currently trying to expose a c++ Interface (pure virtual class) to Python using Boost::Python. The c++ interface is:</p> <h2>Agent.hpp</h2> <pre><code>#include "Tab.hpp" class Agent { virtual void start(const Tab&amp; t) = 0; virtual void stop() = 0; }; </code></pre> <p>And, by reading the "official" ...
2
2010-02-16T22:53:26Z
2,277,729
<p>The get_override functions returns an an object of type <a href="http://www.cs.brown.edu/~jwicks/boost/libs/python/doc/v2/wrapper.html#override-spec" rel="nofollow">override</a> which has a number of overloads for differing number of arguments. So you should be able to just do this:</p> <pre><code>void start(const ...
3
2010-02-17T01:28:10Z
[ "c++", "python", "interface", "wrapping", "boost-python" ]
python: Regex matching file extension
2,277,030
<p>hi i am trying to get the extension of the file called in a url (eg <code>/wp-includes/js/jquery/jquery.js?ver=1.3.2 HTTP/1.1</code>) and get the query parameters passed to the file too.</p> <p>What would be the best way to the extension? </p>
3
2010-02-16T22:57:20Z
2,277,049
<p><a href="http://docs.python.org/library/urlparse.html#urlparse.urlparse"><code>urlparse.urlparse()</code></a> and <a href="http://docs.python.org/library/os.path.html#os.path.splitext"><code>os.path.splitext()</code></a>.</p>
7
2010-02-16T22:59:59Z
[ "python", "regex" ]
Deleting a file
2,277,236
<pre><code>from Tkinter import * import socket, sys, os import tkMessageBox root = Tk() root.title("File Deleter v1.0") root.config(bg='black') root.resizable(0, 0) text = Text() text3 = Text() frame = Frame(root) frame.config(bg="black") frame.pack(pady=10, padx=5) frame1 = Frame(root) frame1.config(bg="black") fr...
1
2010-02-16T23:37:29Z
2,277,287
<p>Perhaps x is not what you think it is, just a guess but maybe there a some whitespace there or somthing, try this to check</p> <pre><code>def button1(): try: x = text.get("1.0", END) print repr(x) os.remove(x) except WindowsError, e: print e text3.insert(END, "File No...
0
2010-02-16T23:47:53Z
[ "python", "tkinter" ]
Deleting a file
2,277,236
<pre><code>from Tkinter import * import socket, sys, os import tkMessageBox root = Tk() root.title("File Deleter v1.0") root.config(bg='black') root.resizable(0, 0) text = Text() text3 = Text() frame = Frame(root) frame.config(bg="black") frame.pack(pady=10, padx=5) frame1 = Frame(root) frame1.config(bg="black") fr...
1
2010-02-16T23:37:29Z
2,277,325
<p>When I run this code on Linux and place a breakpoint in <code>button1()</code>, I see that the value of <code>x</code> includes a trailing newline character. That means the <code>os.remove()</code> call won't work, because the filename I typed in didn't actually contain a newline. If I remove the trailing newline, t...
3
2010-02-16T23:55:52Z
[ "python", "tkinter" ]
Deleting a file
2,277,236
<pre><code>from Tkinter import * import socket, sys, os import tkMessageBox root = Tk() root.title("File Deleter v1.0") root.config(bg='black') root.resizable(0, 0) text = Text() text3 = Text() frame = Frame(root) frame.config(bg="black") frame.pack(pady=10, padx=5) frame1 = Frame(root) frame1.config(bg="black") fr...
1
2010-02-16T23:37:29Z
2,277,337
<p>I believe gnibbler is on track with whitespace being the problem. The Text Widget gives you endline characters \n. Try adding a .strip() to the end of your text.get or you can use an Entry widget as opposed to a Text Widget since your Text widget is only one line anways.</p> <pre><code>x = text.get('1.0', END).st...
0
2010-02-16T23:58:14Z
[ "python", "tkinter" ]
How do I url unencode in Python?
2,277,302
<p>GIven this: It%27s%20me%21</p> <p>Unencode it and turn it into regular text?</p>
10
2010-02-16T23:50:49Z
2,277,313
<p>Take a look at <code>urllib.unquote</code> and <code>urllib.unquote_plus</code>. That will address your problem. Technically though url "encoding" is the process of passing arguments into a url with the &amp; and ? characters (e.g. <code>www.foo.com?x=11&amp;y=12</code>).</p>
9
2010-02-16T23:52:56Z
[ "python", "url", "encoding" ]
How do I url unencode in Python?
2,277,302
<p>GIven this: It%27s%20me%21</p> <p>Unencode it and turn it into regular text?</p>
10
2010-02-16T23:50:49Z
2,277,320
<p>Use the <a href="http://docs.python.org/library/urllib.html#urllib.unquote" rel="nofollow">unquote</a> method from <a href="http://docs.python.org/library/urllib.html#module-urllib" rel="nofollow">urllib</a>.</p> <pre><code>&gt;&gt;&gt; from urllib import unquote &gt;&gt;&gt; unquote('It%27s%20me%21') "It's me!" </...
4
2010-02-16T23:54:41Z
[ "python", "url", "encoding" ]
How do I url unencode in Python?
2,277,302
<p>GIven this: It%27s%20me%21</p> <p>Unencode it and turn it into regular text?</p>
10
2010-02-16T23:50:49Z
2,277,323
<p>in python2</p> <pre><code>&gt;&gt;&gt; import urlparse &gt;&gt;&gt; urlparse.unquote('It%27s%20me%21') "It's me!" </code></pre> <p>In python3</p> <pre><code>&gt;&gt;&gt; import urllib.parse &gt;&gt;&gt; urllib.parse.unquote('It%27s%20me%21') "It's me!" </code></pre>
12
2010-02-16T23:55:07Z
[ "python", "url", "encoding" ]
Python: Split a string at uppercase letters
2,277,352
<p>What is the pythonic way to split a string before the occurrences of a given set of characters?</p> <p>For example, I want to split <code>'TheLongAndWindingRoad'</code> at any occurrence of an uppercase letter (possibly except the first), and obtain <code>['The', 'Long', 'And', 'Winding', 'Road']</code>.</p> <p>E...
34
2010-02-17T00:01:22Z
2,277,363
<p>Unfortunately it's not possible to <a href="http://bugs.python.org/issue3262">split on a zero-width match</a> in Python. But you can use <code>re.findall</code> instead:</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; re.findall('[A-Z][^A-Z]*', 'TheLongAndWindingRoad') ['The', 'Long', 'And', 'Winding', 'Road'] &...
50
2010-02-17T00:04:44Z
[ "python", "regex", "string" ]
Python: Split a string at uppercase letters
2,277,352
<p>What is the pythonic way to split a string before the occurrences of a given set of characters?</p> <p>For example, I want to split <code>'TheLongAndWindingRoad'</code> at any occurrence of an uppercase letter (possibly except the first), and obtain <code>['The', 'Long', 'And', 'Winding', 'Road']</code>.</p> <p>E...
34
2010-02-17T00:01:22Z
2,277,374
<pre><code>import re filter(None, re.split("([A-Z][^A-Z]*)", "TheLongAndWindingRoad")) </code></pre> <p>or</p> <pre><code>[s for s in re.split("([A-Z][^A-Z]*)", "TheLongAndWindingRoad") if s] </code></pre>
4
2010-02-17T00:07:51Z
[ "python", "regex", "string" ]
Python: Split a string at uppercase letters
2,277,352
<p>What is the pythonic way to split a string before the occurrences of a given set of characters?</p> <p>For example, I want to split <code>'TheLongAndWindingRoad'</code> at any occurrence of an uppercase letter (possibly except the first), and obtain <code>['The', 'Long', 'And', 'Winding', 'Road']</code>.</p> <p>E...
34
2010-02-17T00:01:22Z
2,277,407
<pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; re.findall('[A-Z][a-z]*', 'TheLongAndWindingRoad') ['The', 'Long', 'And', 'Winding', 'Road'] &gt;&gt;&gt; re.findall('[A-Z][a-z]*', 'SplitAString') ['Split', 'A', 'String'] &gt;&gt;&gt; re.findall('[A-Z][a-z]*', 'ABC') ['A', 'B', 'C'] </code></pre> <p>If you want <code>...
14
2010-02-17T00:14:03Z
[ "python", "regex", "string" ]
Python: Split a string at uppercase letters
2,277,352
<p>What is the pythonic way to split a string before the occurrences of a given set of characters?</p> <p>For example, I want to split <code>'TheLongAndWindingRoad'</code> at any occurrence of an uppercase letter (possibly except the first), and obtain <code>['The', 'Long', 'And', 'Winding', 'Road']</code>.</p> <p>E...
34
2010-02-17T00:01:22Z
2,277,521
<p>Alternative solution (if you dislike explicit regexes):</p> <pre><code>s = 'TheLongAndWindingRoad' pos = [i for i,e in enumerate(s) if e.isupper()] parts = [] for j in xrange(len(pos)): try: parts.append(s[pos[j]:pos[j+1]]) except IndexError: parts.append(s[pos[j]:]) print parts </code></...
2
2010-02-17T00:37:13Z
[ "python", "regex", "string" ]
Python: Split a string at uppercase letters
2,277,352
<p>What is the pythonic way to split a string before the occurrences of a given set of characters?</p> <p>For example, I want to split <code>'TheLongAndWindingRoad'</code> at any occurrence of an uppercase letter (possibly except the first), and obtain <code>['The', 'Long', 'And', 'Winding', 'Road']</code>.</p> <p>E...
34
2010-02-17T00:01:22Z
2,277,852
<p>A variation on @ChristopheD 's solution</p> <pre><code>s = 'TheLongAndWindingRoad' pos = [i for i,e in enumerate(s+'A') if e.isupper()] parts = [s[pos[j]:pos[j+1]] for j in xrange(len(pos)-1)] print parts </code></pre>
3
2010-02-17T02:01:39Z
[ "python", "regex", "string" ]
Python: Split a string at uppercase letters
2,277,352
<p>What is the pythonic way to split a string before the occurrences of a given set of characters?</p> <p>For example, I want to split <code>'TheLongAndWindingRoad'</code> at any occurrence of an uppercase letter (possibly except the first), and obtain <code>['The', 'Long', 'And', 'Winding', 'Road']</code>.</p> <p>E...
34
2010-02-17T00:01:22Z
2,279,177
<p>Here is an alternative regex solution. The problem can be reprased as "how do I insert a space before each uppercase letter, before doing the split":</p> <pre><code>&gt;&gt;&gt; s = "TheLongAndWindingRoad ABC A123B45" &gt;&gt;&gt; re.sub( r"([A-Z])", r" \1", s).split() ['The', 'Long', 'And', 'Winding', 'Road', 'A'...
12
2010-02-17T08:19:04Z
[ "python", "regex", "string" ]
Python: Split a string at uppercase letters
2,277,352
<p>What is the pythonic way to split a string before the occurrences of a given set of characters?</p> <p>For example, I want to split <code>'TheLongAndWindingRoad'</code> at any occurrence of an uppercase letter (possibly except the first), and obtain <code>['The', 'Long', 'And', 'Winding', 'Road']</code>.</p> <p>E...
34
2010-02-17T00:01:22Z
24,609,109
<pre><code>src = 'TheLongAndWindingRoad' glue = ' ' result = ''.join(glue + x if x.isupper() else x for x in src).strip(glue).split(glue) </code></pre>
1
2014-07-07T11:04:03Z
[ "python", "regex", "string" ]
Python: Split a string at uppercase letters
2,277,352
<p>What is the pythonic way to split a string before the occurrences of a given set of characters?</p> <p>For example, I want to split <code>'TheLongAndWindingRoad'</code> at any occurrence of an uppercase letter (possibly except the first), and obtain <code>['The', 'Long', 'And', 'Winding', 'Road']</code>.</p> <p>E...
34
2010-02-17T00:01:22Z
27,340,398
<p>An alternative way without using regex or enumerate:</p> <pre><code>word = 'TheLongAndWindingRoad' list = [x for x in word] for char in list: if char != list[0] and char.isupper(): list[list.index(char)] = ' ' + char fin_list = ''.join(list).split(' ') </code></pre> <p>I think it is clearer and simpl...
0
2014-12-07T06:48:06Z
[ "python", "regex", "string" ]
Python: Split a string at uppercase letters
2,277,352
<p>What is the pythonic way to split a string before the occurrences of a given set of characters?</p> <p>For example, I want to split <code>'TheLongAndWindingRoad'</code> at any occurrence of an uppercase letter (possibly except the first), and obtain <code>['The', 'Long', 'And', 'Winding', 'Road']</code>.</p> <p>E...
34
2010-02-17T00:01:22Z
35,315,799
<p>An alternate way using <strong><code>enumerate</code></strong> and <strong><code>isupper()</code></strong></p> <p><strong>Code:</strong></p> <pre><code>strs = 'TheLongAndWindingRoad' ind =0 count =0 new_lst=[] for index, val in enumerate(strs[1:],1): if val.isupper(): new_lst.append(strs[ind:index]) ...
0
2016-02-10T12:50:56Z
[ "python", "regex", "string" ]
How can I keep a Python script command window open when opened from a .Net application?
2,277,571
<p>Now the obvious answer is to just open the script from a command line, but that isn't an option. I'm writing a simple application to syntax highlight Python and then run the scripts from the same program. A Python IDE if you will. The scripts I want to run are entirely command line programs.</p> <p>I'm using a S...
1
2010-02-17T00:45:57Z
2,277,615
<p>Don't use a Windows console. Create your own console panel or window which attaches to the stdin, stdout, and stderr of the interpreter executable. Or <a href="http://docs.python.org/extending/index.html" rel="nofollow">embed your own interpreter</a>.</p>
1
2010-02-17T00:57:52Z
[ "c#", "python", "command-line" ]
How can I keep a Python script command window open when opened from a .Net application?
2,277,571
<p>Now the obvious answer is to just open the script from a command line, but that isn't an option. I'm writing a simple application to syntax highlight Python and then run the scripts from the same program. A Python IDE if you will. The scripts I want to run are entirely command line programs.</p> <p>I'm using a S...
1
2010-02-17T00:45:57Z
7,886,740
<p>I had a similar issue, I solved it by adding raw_input() at the end of the script. Even if it's not using the value the script should hold before quitting as it waits for input from the command line.</p> <p>Sadly this doesn't help if the script errors out before it reaches the raw_input() line, but you'll see how ...
0
2011-10-25T08:40:41Z
[ "c#", "python", "command-line" ]
merging dictionaries in python
2,277,895
<p>Hey everyone, Sorry for the very general title but I'll try to be as specific as possible. </p> <p>I am working on a text mining application. I have a large number of key value pairs of the form ((word, corpus) -> occurence_count) (everything is an integer) which I am storing in multiple python dictionaries (tuple-...
2
2010-02-17T02:13:21Z
2,277,931
<p>Something like this, if I understand your question correctly</p> <pre><code>from collections import defaultdict import pickle result = defaultdict(int) for fn in filenames: data_dict = pickle.load(open(fn)) for k,count in data_dict.items(): word,corpus = k result[k]+=count </code></pre>
0
2010-02-17T02:25:48Z
[ "python", "dictionary", "merge" ]
merging dictionaries in python
2,277,895
<p>Hey everyone, Sorry for the very general title but I'll try to be as specific as possible. </p> <p>I am working on a text mining application. I have a large number of key value pairs of the form ((word, corpus) -> occurence_count) (everything is an integer) which I am storing in multiple python dictionaries (tuple-...
2
2010-02-17T02:13:21Z
2,277,941
<p>A disk-based dictionary-like exists -- see the <a href="http://docs.python.org/library/shelve.html?highlight=shelve#module-shelve" rel="nofollow">shelve</a> module. Keys into a shelf must be strings, but you could simply use <code>str</code> on your tuples to obtain equivalent string keys; plus, I read your Q as me...
2
2010-02-17T02:29:11Z
[ "python", "dictionary", "merge" ]
merging dictionaries in python
2,277,895
<p>Hey everyone, Sorry for the very general title but I'll try to be as specific as possible. </p> <p>I am working on a text mining application. I have a large number of key value pairs of the form ((word, corpus) -> occurence_count) (everything is an integer) which I am storing in multiple python dictionaries (tuple-...
2
2010-02-17T02:13:21Z
2,278,164
<ol> <li><p>If I understood your question correctly and you have integer ids for the words and corpora, then you can gain some performance by switching from a dict to a list, or even better, a numpy array. This may be annoying! </p> <p>Basically, you need to replace the tuple with a single integer, which we can call t...
0
2010-02-17T03:42:42Z
[ "python", "dictionary", "merge" ]
What exactly is meant when mr.developer says "The package 'django-quoteme' is dirty."
2,277,926
<p>I'm using mr.developer to track some packages on github. When I rerun my buildout, I get:</p> <p>The package 'django-quoteme' is dirty.</p> <p>Do you want to update it anyway? [yes/No/all] y</p> <p>What is meant by "dirty" exactly?</p>
3
2010-02-17T02:23:23Z
2,277,936
<p>I don't know what it means specifically in this context, but in the computing science world, "dirty" usually means its been modified. Maybe one the files in the package has been edited, and by updating it, you'll lose those changes, hence the warning.</p> <p><a href="http://en.wikipedia.org/wiki/Dirty_%28computer_s...
4
2010-02-17T02:27:10Z
[ "python", "django", "buildout" ]
What exactly is meant when mr.developer says "The package 'django-quoteme' is dirty."
2,277,926
<p>I'm using mr.developer to track some packages on github. When I rerun my buildout, I get:</p> <p>The package 'django-quoteme' is dirty.</p> <p>Do you want to update it anyway? [yes/No/all] y</p> <p>What is meant by "dirty" exactly?</p>
3
2010-02-17T02:23:23Z
2,277,938
<p>From <a href="http://github.com/fschulze/mr.developer" rel="nofollow">http://github.com/fschulze/mr.developer</a>:</p> <blockquote> <p>Dirty SVN</p> <p>You get an error like::</p> <p>ERROR: Can't switch package 'foo' from 'https://example.com/svn/foo/trunk/', because it's dirty.</p> <p>If you...
5
2010-02-17T02:28:27Z
[ "python", "django", "buildout" ]
How do I work around this problem creating a virtualenv environment with a custom-build Python?
2,278,028
<p>I need to run some code on a Linux machine with Python 2.3.4 pre-installed. I'm not on the sudoers list for that machine, so I built Python 2.6.4 into (a subdirectory in) my home directory. Then I attempted to use virtualenv (for the first time), but got:</p> <pre><code>$ Python-2.6.4/python virtualenv/virtualenv...
2
2010-02-17T02:59:29Z
2,278,059
<p>Have you actually run "make install" on your custom python build? Usually you'll want to do something like</p> <pre><code>./configure --prefix=/path/to/installdir (other options) make make install </code></pre> <p><strong>Note</strong> Prefix can be any directory you have full write-permissions to, for example I ...
6
2010-02-17T03:07:27Z
[ "python", "virtualenv" ]
How do I work around this problem creating a virtualenv environment with a custom-build Python?
2,278,028
<p>I need to run some code on a Linux machine with Python 2.3.4 pre-installed. I'm not on the sudoers list for that machine, so I built Python 2.6.4 into (a subdirectory in) my home directory. Then I attempted to use virtualenv (for the first time), but got:</p> <pre><code>$ Python-2.6.4/python virtualenv/virtualenv...
2
2010-02-17T02:59:29Z
2,278,086
<p>In addition to Crast's suggestion of making sure you actually installed your custom compiled Python, you should also check that the custom Python can actually find its libraries. This is the hint you're getting with the message about <a href="http://docs.python.org/install/index.html#modifying-python-s-search-path" ...
2
2010-02-17T03:21:39Z
[ "python", "virtualenv" ]
How do I work around this problem creating a virtualenv environment with a custom-build Python?
2,278,028
<p>I need to run some code on a Linux machine with Python 2.3.4 pre-installed. I'm not on the sudoers list for that machine, so I built Python 2.6.4 into (a subdirectory in) my home directory. Then I attempted to use virtualenv (for the first time), but got:</p> <pre><code>$ Python-2.6.4/python virtualenv/virtualenv...
2
2010-02-17T02:59:29Z
7,472,635
<p>I had the same error when trying to install on an existing directory that already had easy_install in lib/python2.6. I had to put a link from lib64/python2.6 to lib/python2.6.</p> <p>I am not saying my fix is the right fix, rather, I'm pointing to another reason why you might get this error.</p>
1
2011-09-19T14:37:28Z
[ "python", "virtualenv" ]
How do I work around this problem creating a virtualenv environment with a custom-build Python?
2,278,028
<p>I need to run some code on a Linux machine with Python 2.3.4 pre-installed. I'm not on the sudoers list for that machine, so I built Python 2.6.4 into (a subdirectory in) my home directory. Then I attempted to use virtualenv (for the first time), but got:</p> <pre><code>$ Python-2.6.4/python virtualenv/virtualenv...
2
2010-02-17T02:59:29Z
17,286,080
<p>Now you can easily install Python as an unpriviledged user using Anaconda: <a href="http://continuum.io/downloads" rel="nofollow">http://continuum.io/downloads</a></p> <p>It's similar to this question. Once of the answers details making a new environment, so you don't need to use virtual-env and avoid the occasion...
0
2013-06-24T22:17:04Z
[ "python", "virtualenv" ]
How do I work around this problem creating a virtualenv environment with a custom-build Python?
2,278,028
<p>I need to run some code on a Linux machine with Python 2.3.4 pre-installed. I'm not on the sudoers list for that machine, so I built Python 2.6.4 into (a subdirectory in) my home directory. Then I attempted to use virtualenv (for the first time), but got:</p> <pre><code>$ Python-2.6.4/python virtualenv/virtualenv...
2
2010-02-17T02:59:29Z
28,327,883
<p>I don't have enough rep to add this as a comment on @Crast's answer and this question is 4 years old, but this might be useful to someone. In Windows, you have to path out to <strong>python.exe</strong>, but it seems that in Linux/OS X you just path to the folder. Example:</p> <p><strong>Windows:</strong></p> <pr...
0
2015-02-04T17:42:55Z
[ "python", "virtualenv" ]
Count number of records by date in Django
2,278,076
<p>I have a model similar to the following:</p> <pre><code>class Review(models.Model): venue = models.ForeignKey(Venue, db_index=True) review = models.TextField() datetime_created = models.DateTimeField(default=datetime.now) </code></pre> <p>I'd like to query the database to get the total number of revi...
33
2010-02-17T03:16:54Z
2,283,388
<p>If you were storing a date field, you could use this:</p> <pre><code>from django.db.models import Count Review.objects.filter(venue__pk = 2) .values('date').annotate(event_count = Count('id')) </code></pre> <p>Because you're storing datetime, it's a little more complicated, but this should offer a good starti...
10
2010-02-17T18:32:57Z
[ "python", "django", "django-models", "django-queryset", "django-1.1" ]
Count number of records by date in Django
2,278,076
<p>I have a model similar to the following:</p> <pre><code>class Review(models.Model): venue = models.ForeignKey(Venue, db_index=True) review = models.TextField() datetime_created = models.DateTimeField(default=datetime.now) </code></pre> <p>I'd like to query the database to get the total number of revi...
33
2010-02-17T03:16:54Z
2,283,913
<p>This should work (using the same MySQL specific function you used):</p> <pre><code>Review.objects.filter(venue__pk=2) .extra({'date_created' : "date(datetime_created)"}) .values('date_created') .annotate(created_count=Count('id')) </code></pre>
71
2010-02-17T19:51:30Z
[ "python", "django", "django-models", "django-queryset", "django-1.1" ]
Count number of records by date in Django
2,278,076
<p>I have a model similar to the following:</p> <pre><code>class Review(models.Model): venue = models.ForeignKey(Venue, db_index=True) review = models.TextField() datetime_created = models.DateTimeField(default=datetime.now) </code></pre> <p>I'd like to query the database to get the total number of revi...
33
2010-02-17T03:16:54Z
34,457,128
<p>Just for completeness, since extra() is aimed for deprecation, one could use this approach:</p> <pre><code>from django.db.models.expressions import DateTime Review.objects.all().\ annotate(month=DateTime("timestamp", "month", pytz.timezone("Etc/UTC"))).\ values("month").\ annotate(created_count=Count('...
5
2015-12-24T19:25:57Z
[ "python", "django", "django-models", "django-queryset", "django-1.1" ]
Count number of records by date in Django
2,278,076
<p>I have a model similar to the following:</p> <pre><code>class Review(models.Model): venue = models.ForeignKey(Venue, db_index=True) review = models.TextField() datetime_created = models.DateTimeField(default=datetime.now) </code></pre> <p>I'd like to query the database to get the total number of revi...
33
2010-02-17T03:16:54Z
36,540,724
<p>Also you can define custom function:</p> <pre><code>from django.db.models.expressions import Func # create custom sql function class ExtractDateFunction(Func): function = "DATE" # thats the name of function, the way it mapped to sql # pass this function to annotate Review.objects.filter(venue__pk=2) .an...
0
2016-04-11T05:50:23Z
[ "python", "django", "django-models", "django-queryset", "django-1.1" ]
detecting end of tty output
2,278,150
<p>Hi I'm writing a psudo-terminal that can live in a tty and spawn a second tty which is filters input and output from</p> <p>I'm writing it in python for now, spawning the second tty and reading and writing is easy</p> <p>but when I read, the read does not end, it waits for more input.</p> <pre><code>import subpro...
1
2010-02-17T03:37:35Z
2,278,161
<p>For applications like a shell, the output will not end until the shell ends. Either use <a href="http://docs.python.org/library/select.html#select.select" rel="nofollow"><code>select.select()</code></a> to check if it has more output waiting for you, or end the process.</p>
0
2010-02-17T03:42:03Z
[ "python", "tty", "control-characters" ]
detecting end of tty output
2,278,150
<p>Hi I'm writing a psudo-terminal that can live in a tty and spawn a second tty which is filters input and output from</p> <p>I'm writing it in python for now, spawning the second tty and reading and writing is easy</p> <p>but when I read, the read does not end, it waits for more input.</p> <pre><code>import subpro...
1
2010-02-17T03:37:35Z
2,278,162
<p>Well, your output actually hasn't completed. Because you spawned <code>/bin/sh</code>, the shell is still running after "ls" completes. There is no EOF indicator, because it's still running.</p> <p>Why not simply run <code>/bin/ls</code>?</p> <p>You could do something like</p> <pre><code>pfd = subprocess.Popen(['...
1
2010-02-17T03:42:15Z
[ "python", "tty", "control-characters" ]
OpenCV Image Processing -- C++ vs C vs Python
2,278,228
<p>I was thinking of trying OpenCV for a project and noticed that it had C, C++ and Python.</p> <p>I am trying to figure out whether I should use C++, C or Python -- and would like to use whatever has the best OpenCV support. </p> <p>Just from looking at the index page for the various documentation it looks like the...
20
2010-02-17T04:04:40Z
2,278,331
<p>The Python interface is still being developed whereas the C++ interface (especially with the new <code>Mat</code> class) is quite mature. If you're comfortable in C++, I would highly recommend using it - else, you can start using Python and contribute back any features you think OpenCV needs :)</p>
10
2010-02-17T04:35:31Z
[ "c++", "python", "c", "opencv" ]
OpenCV Image Processing -- C++ vs C vs Python
2,278,228
<p>I was thinking of trying OpenCV for a project and noticed that it had C, C++ and Python.</p> <p>I am trying to figure out whether I should use C++, C or Python -- and would like to use whatever has the best OpenCV support. </p> <p>Just from looking at the index page for the various documentation it looks like the...
20
2010-02-17T04:04:40Z
5,362,904
<p>Actually Python binding was finished <a href="http://opencv.willowgarage.com/wiki/PythonInterface">starting with release 2.2</a>. So i would go with python if i were you, because the performance will be almost the same anyway as you are using c libraries in both cases. However python will get you there faster, safel...
13
2011-03-19T15:06:58Z
[ "c++", "python", "c", "opencv" ]
OpenCV Image Processing -- C++ vs C vs Python
2,278,228
<p>I was thinking of trying OpenCV for a project and noticed that it had C, C++ and Python.</p> <p>I am trying to figure out whether I should use C++, C or Python -- and would like to use whatever has the best OpenCV support. </p> <p>Just from looking at the index page for the various documentation it looks like the...
20
2010-02-17T04:04:40Z
10,057,553
<p>I think it depends how proficient you are in C++. The Mat interface does appear more modern than the old IPLImage C interface. The problem I'm having is that most of the examples you'll find on the web, or even here on stackoverflow are for the C interface (e.g. cvCvtColor), not for the C++ interface. So I'm really ...
4
2012-04-07T19:18:42Z
[ "c++", "python", "c", "opencv" ]
OpenCV Image Processing -- C++ vs C vs Python
2,278,228
<p>I was thinking of trying OpenCV for a project and noticed that it had C, C++ and Python.</p> <p>I am trying to figure out whether I should use C++, C or Python -- and would like to use whatever has the best OpenCV support. </p> <p>Just from looking at the index page for the various documentation it looks like the...
20
2010-02-17T04:04:40Z
16,210,061
<p>Even if you're very proficient in C or C++, you should use python to speed up your development (I should guess a 4x factor). Performance are really quite the same.</p>
1
2013-04-25T08:36:37Z
[ "c++", "python", "c", "opencv" ]
Python UUID represented as special characters
2,278,239
<p>When creating a UUID in Python, likeso:</p> <pre><code>&gt;&gt;&gt; uuid.uuid1() UUID('a8098c1a-f86e-11da-bd1a-00112444be1e') </code></pre> <p>How could one map that UUID into a string made up of the capitalized alphabet A-Z minus the characters D, F, I, O, Q, and U, plus the numerical digits, plus the characters ...
1
2010-02-17T04:07:31Z
2,278,300
<p>How important is it to you to "squeeze" the representation by 18.75%, i.e., from 32 to 26 characters? Because, if saving this small percentage of bytes isn't absolutely crucial, something like <code>uid.hex.upper().replace('D','Z')</code> will do what you ask (not using the whole alphabet you make available, but t...
2
2010-02-17T04:24:54Z
[ "python", "algorithm", "uuid", "transpose", "isomorphism" ]
Python UUID represented as special characters
2,278,239
<p>When creating a UUID in Python, likeso:</p> <pre><code>&gt;&gt;&gt; uuid.uuid1() UUID('a8098c1a-f86e-11da-bd1a-00112444be1e') </code></pre> <p>How could one map that UUID into a string made up of the capitalized alphabet A-Z minus the characters D, F, I, O, Q, and U, plus the numerical digits, plus the characters ...
1
2010-02-17T04:07:31Z
2,278,329
<pre><code>&gt;&gt;&gt; OCRf = 'ABCEGHJKLMNPRSTVWXYZ1234567890+=' &gt;&gt;&gt; uuid = 'a8098c1a-f86e-11da-bd1a-00112444be1e' &gt;&gt;&gt; binstr = bin(int(uuid.replace("-",""),16))[2:].zfill(130) &gt;&gt;&gt; ocfstr = "".join(OCRf[int(binstr[i:i+5],2)] for i in range(0,130,5)) &gt;&gt;&gt; ocfstr 'HLBJJB2+ETCKSP7JWACGY...
1
2010-02-17T04:34:38Z
[ "python", "algorithm", "uuid", "transpose", "isomorphism" ]
Python UUID represented as special characters
2,278,239
<p>When creating a UUID in Python, likeso:</p> <pre><code>&gt;&gt;&gt; uuid.uuid1() UUID('a8098c1a-f86e-11da-bd1a-00112444be1e') </code></pre> <p>How could one map that UUID into a string made up of the capitalized alphabet A-Z minus the characters D, F, I, O, Q, and U, plus the numerical digits, plus the characters ...
1
2010-02-17T04:07:31Z
2,279,142
<pre><code>transtbl = string.maketrans( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', 'ABCEGHJKLMNPRSTVWXYZ1234567890+=' ) uuidstr = uuid.uuid1() print base64.b32encode(str(uuidstr).replace('-', '').decode('hex')).rstrip('=').translate(transtbl) </code></pre> <p>Yes, this method <em>does</em> make me a bit ill, thanks for...
1
2010-02-17T08:04:13Z
[ "python", "algorithm", "uuid", "transpose", "isomorphism" ]
Pinax (13, 'Permission denied')
2,278,394
<p>I'm a noob but I made my application work beautifully using <code>python manage.py runserver</code> but when I brought it to Apache + mod_wsgi, I keep getting this error. The debug messages aren't much help. Here is a screenshot of the entire debug image: <a href="http://img694.imageshack.us/img694/6723/screenshotfb...
0
2010-02-17T04:49:56Z
2,278,436
<p>Under Apache/mod_wsgi your code will run as Apache user and will not usually have access rights to write to directories that you as a user has. Read:</p> <p><a href="http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Access_Rights_Of_Apache_User" rel="nofollow">http://code.google.com/p/modwsgi/wiki/Application...
4
2010-02-17T05:01:54Z
[ "python", "django", "deployment", "wsgi", "pinax" ]
Pinax (13, 'Permission denied')
2,278,394
<p>I'm a noob but I made my application work beautifully using <code>python manage.py runserver</code> but when I brought it to Apache + mod_wsgi, I keep getting this error. The debug messages aren't much help. Here is a screenshot of the entire debug image: <a href="http://img694.imageshack.us/img694/6723/screenshotfb...
0
2010-02-17T04:49:56Z
4,807,279
<p>You are logging in as root when you use 'python manage.py runserver' which is why it is allowed to write to that director but when apache launches your wsgi script it will be under its user name which isnt allowed to write in the directory you have your python scripts in.</p> <p>Assuming you are using ubuntu server...
0
2011-01-26T16:47:41Z
[ "python", "django", "deployment", "wsgi", "pinax" ]
Inner Classes: How can I get the outer-class object at construction time?
2,278,426
<p>Consider the following Python (runs in 2.x or 3.x):</p> <pre><code>class Outer(object): pass class Inner(object): def __init__(self): print("Inner.self", self) o = Outer() i = o.Inner() </code></pre> <p>I want to get my hands on <code>o</code> while inside <code>Inner.__init__()</code>. But:</p> ...
5
2010-02-17T04:59:57Z
2,278,480
<p>You should redesign your code not to use inner classes and to explicitly pass the instance of Outer to Inner when you make it, or not to require it.</p>
0
2010-02-17T05:13:14Z
[ "python" ]
Inner Classes: How can I get the outer-class object at construction time?
2,278,426
<p>Consider the following Python (runs in 2.x or 3.x):</p> <pre><code>class Outer(object): pass class Inner(object): def __init__(self): print("Inner.self", self) o = Outer() i = o.Inner() </code></pre> <p>I want to get my hands on <code>o</code> while inside <code>Inner.__init__()</code>. But:</p> ...
5
2010-02-17T04:59:57Z
2,278,486
<p>You can't (in any portable, reliable or efficient way.) Nested classes have no relation to the nesting class. They have no added value, either. Instead of using nested classes, use containment of instances -- define <code>Outer</code> and <code>Inner</code> separately, and create an instance of <code>Inner</code> in...
0
2010-02-17T05:15:04Z
[ "python" ]
Inner Classes: How can I get the outer-class object at construction time?
2,278,426
<p>Consider the following Python (runs in 2.x or 3.x):</p> <pre><code>class Outer(object): pass class Inner(object): def __init__(self): print("Inner.self", self) o = Outer() i = o.Inner() </code></pre> <p>I want to get my hands on <code>o</code> while inside <code>Inner.__init__()</code>. But:</p> ...
5
2010-02-17T04:59:57Z
2,278,496
<p>Can't be done. But with a bit of redesign:</p> <pre><code>class Outer(object): pass class _Inner(object): def __init__(self, outobj): self.outobj = outobj def Inner(self): return self._Inner(self) o = Outer() i = o.Inner() print o, i.outobj </code></pre>
2
2010-02-17T05:17:17Z
[ "python" ]
Inner Classes: How can I get the outer-class object at construction time?
2,278,426
<p>Consider the following Python (runs in 2.x or 3.x):</p> <pre><code>class Outer(object): pass class Inner(object): def __init__(self): print("Inner.self", self) o = Outer() i = o.Inner() </code></pre> <p>I want to get my hands on <code>o</code> while inside <code>Inner.__init__()</code>. But:</p> ...
5
2010-02-17T04:59:57Z
2,278,595
<p>In Python 2.6, a class decorator that's also a custom descriptor matches the specs you give:</p> <pre><code>class InnerClassDescriptor(object): def __init__(self, cls): self.cls = cls def __get__(self, instance, outerclass): class Wrapper(self.cls): outer = instance Wrapper.__name__ = self.cls...
11
2010-02-17T05:47:31Z
[ "python" ]
Inner Classes: How can I get the outer-class object at construction time?
2,278,426
<p>Consider the following Python (runs in 2.x or 3.x):</p> <pre><code>class Outer(object): pass class Inner(object): def __init__(self): print("Inner.self", self) o = Outer() i = o.Inner() </code></pre> <p>I want to get my hands on <code>o</code> while inside <code>Inner.__init__()</code>. But:</p> ...
5
2010-02-17T04:59:57Z
2,282,096
<p>You can use a metaclass to implement a <a href="http://docs.python.org/reference/datamodel.html?highlight=__get__#object.__get__" rel="nofollow">_<em>get</em>_</a> descriptor that binds the inner class to the outer one. And since you seem to be interested in only binding to a class, consider modifying the inner cla...
2
2010-02-17T15:49:20Z
[ "python" ]
Inner Classes: How can I get the outer-class object at construction time?
2,278,426
<p>Consider the following Python (runs in 2.x or 3.x):</p> <pre><code>class Outer(object): pass class Inner(object): def __init__(self): print("Inner.self", self) o = Outer() i = o.Inner() </code></pre> <p>I want to get my hands on <code>o</code> while inside <code>Inner.__init__()</code>. But:</p> ...
5
2010-02-17T04:59:57Z
35,118,984
<p>See <a href="http://stackoverflow.com/questions/2024566/access-outer-class-from-inner-class-in-python/35118717#35118717">Access outer class from inner class in python</a> (<a href="http://stackoverflow.com/a/35118717/3787376">http://stackoverflow.com/a/35118717/3787376</a>) <br>for a good simple working answer I mad...
0
2016-01-31T20:19:10Z
[ "python" ]
Getting UTC offset for a datetime
2,278,477
<p>I have tried this but its not correct:</p> <pre><code>In [34]: e_now Out[34]: datetime.datetime(2010, 2, 17, 0, 2, 40, 506444, tzinfo=&lt;DstTzInfo 'US/Eastern' EST-1 day, 19:00:00 STD&gt;) In [35]: e_now.utcoffset() Out[35]: datetime.timedelta(-1, 68400) </code></pre>
0
2010-02-17T05:12:02Z
2,278,515
<p>The tzinfo is identified as <code>EST-1 day, 19:00:00</code> -- and the timedelta is given as -1 day, 68400 seconds (i.e., 19 hours, just as in the tzinfo identification). All timezones east of the London-Paris meridian will have -1 day and a positive number of seconds: for example, when it's a second past midnight...
1
2010-02-17T05:23:50Z
[ "python", "datetime" ]
How can I end a string randomly and concatenate another string at the end in Python?
2,278,585
<p>Basicaly I have a user inputted string like:</p> <p>"hi my name is bob"</p> <p>what I would like to do is have my program randomly pick a new ending of the string and end it with my specified ending. </p> <p>For example:</p> <p>"hi my name DUR."</p> <p>"hi mDUR."</p> <p>etc etc</p> <p>I'm kinda new to python ...
0
2010-02-17T05:44:57Z
2,278,605
<p>Something like this: </p> <pre><code>import random s = "hi my name is bob" r = random.randint(0, len(s)) print s[:r] + "DUR" </code></pre> <p>String concatentation is accomplished with <code>+</code>. The <code>[a:b]</code> notation is called a slice. <code>s[:r]</code> returns the first <code>r</code> characters...
4
2010-02-17T05:50:14Z
[ "python", "string", "concatenation" ]
How can I end a string randomly and concatenate another string at the end in Python?
2,278,585
<p>Basicaly I have a user inputted string like:</p> <p>"hi my name is bob"</p> <p>what I would like to do is have my program randomly pick a new ending of the string and end it with my specified ending. </p> <p>For example:</p> <p>"hi my name DUR."</p> <p>"hi mDUR."</p> <p>etc etc</p> <p>I'm kinda new to python ...
0
2010-02-17T05:44:57Z
2,278,608
<pre><code>s[:random.randrange(len(s))] + "DUR" </code></pre>
1
2010-02-17T05:50:59Z
[ "python", "string", "concatenation" ]
How can I end a string randomly and concatenate another string at the end in Python?
2,278,585
<p>Basicaly I have a user inputted string like:</p> <p>"hi my name is bob"</p> <p>what I would like to do is have my program randomly pick a new ending of the string and end it with my specified ending. </p> <p>For example:</p> <p>"hi my name DUR."</p> <p>"hi mDUR."</p> <p>etc etc</p> <p>I'm kinda new to python ...
0
2010-02-17T05:44:57Z
2,278,609
<p>Not sure why you would want this, but you can do something like the following</p> <pre><code>import random user_string = 'hi my name is bob' my_custom_string = 'DUR' print ''.join([x[:random.randint(0, len(user_string))], my_custom_string]) </code></pre> <p>You should read <a href="http://docs.python.org/library/r...
0
2010-02-17T05:50:59Z
[ "python", "string", "concatenation" ]
How can I end a string randomly and concatenate another string at the end in Python?
2,278,585
<p>Basicaly I have a user inputted string like:</p> <p>"hi my name is bob"</p> <p>what I would like to do is have my program randomly pick a new ending of the string and end it with my specified ending. </p> <p>For example:</p> <p>"hi my name DUR."</p> <p>"hi mDUR."</p> <p>etc etc</p> <p>I'm kinda new to python ...
0
2010-02-17T05:44:57Z
2,278,611
<p>just one of the many ways</p> <pre><code>&gt;&gt;&gt; import random &gt;&gt;&gt; specified="DUR" &gt;&gt;&gt; s="hi my name is bob" &gt;&gt;&gt; s[:s.index(random.choice(s))]+specified 'hi mDUR' </code></pre>
0
2010-02-17T05:51:15Z
[ "python", "string", "concatenation" ]
How can I end a string randomly and concatenate another string at the end in Python?
2,278,585
<p>Basicaly I have a user inputted string like:</p> <p>"hi my name is bob"</p> <p>what I would like to do is have my program randomly pick a new ending of the string and end it with my specified ending. </p> <p>For example:</p> <p>"hi my name DUR."</p> <p>"hi mDUR."</p> <p>etc etc</p> <p>I'm kinda new to python ...
0
2010-02-17T05:44:57Z
2,278,617
<p>You can use the random module. See an example below:</p> <pre><code>import random s = "hi my name is bob" pos = random.randint(0, len(s)) s = s[:pos] + "DUR" print s </code></pre>
0
2010-02-17T05:52:12Z
[ "python", "string", "concatenation" ]
cache backend works on devserver but not mod_wsgi
2,278,662
<p>I am using a custom cache backend to wrap the built-in cache backends so that I can add the current site_id to all the cache_keys (this is useful for multi-site functionality with a single memcached instance)</p> <p>unfortunately it works great on the django built-in devserver, but give a nasty error when I try to ...
0
2010-02-17T06:05:17Z
2,278,685
<p>Have you set the <code>CACHE_BACKEND</code> in your settings.py? When DEBUG=True, this is not an issue, as I believe a dummy backend is installed, but in production, you will need to set this value, presumedley even if you're writing your own backend.</p> <p><a href="http://docs.djangoproject.com/en/dev/topics/cac...
1
2010-02-17T06:14:11Z
[ "python", "django", "caching", "memcached" ]
cache backend works on devserver but not mod_wsgi
2,278,662
<p>I am using a custom cache backend to wrap the built-in cache backends so that I can add the current site_id to all the cache_keys (this is useful for multi-site functionality with a single memcached instance)</p> <p>unfortunately it works great on the django built-in devserver, but give a nasty error when I try to ...
0
2010-02-17T06:05:17Z
2,546,213
<p>The root of the issue was <code>sys.path</code> I had to make sure the mod_wsgi set up had the same sys.path as the dev server and that no extra copies of packages were left in places they didn't belong (from refactoring that wasn't applied to the server by version control somehow)</p>
0
2010-03-30T14:58:41Z
[ "python", "django", "caching", "memcached" ]
Question regarding UDP communication in twisted framework
2,278,665
<p>I would like to find out if Twisted imposes restriction on maximum size of UDP packets. The allowable limit on linux platforms is upto 64k (although I intend to send packets of about 10k bytes consisting of JPEG images) but I am not able to send more than approx. 2500 bytes</p>
1
2010-02-17T06:06:15Z
2,278,671
<p>Are you sure that it is not a receive problem?</p> <p>There is no indication that your packets won't be fragmented en route to the destination</p>
-1
2010-02-17T06:08:53Z
[ "python", "udp", "twisted" ]
Question regarding UDP communication in twisted framework
2,278,665
<p>I would like to find out if Twisted imposes restriction on maximum size of UDP packets. The allowable limit on linux platforms is upto 64k (although I intend to send packets of about 10k bytes consisting of JPEG images) but I am not able to send more than approx. 2500 bytes</p>
1
2010-02-17T06:06:15Z
2,280,167
<p>It's very unlikely that Twisted is imposing any limit but there's no reason some other part of the network wouldn't drop the packets if they're too large. It's very rare for people to send UDP packets of such a large size for precisely that sort of reason. Most game applications for example try to keep them below 1....
1
2010-02-17T11:27:49Z
[ "python", "udp", "twisted" ]
what is the usefulness of '>' in python
2,278,901
<pre><code>print 'xxx' &gt; 'ssaww' </code></pre> <p>it print 'true'</p> <p>who can give me a clear example .</p> <p>thanks</p>
0
2010-02-17T07:10:23Z
2,278,906
<p>to order strings syntactically (e.g. alphabetically). </p>
0
2010-02-17T07:11:04Z
[ "python" ]
what is the usefulness of '>' in python
2,278,901
<pre><code>print 'xxx' &gt; 'ssaww' </code></pre> <p>it print 'true'</p> <p>who can give me a clear example .</p> <p>thanks</p>
0
2010-02-17T07:10:23Z
2,278,908
<p>In python strings are ordered <a href="http://en.wikipedia.org/wiki/Lexicographical_order" rel="nofollow">lexicographically</a>.</p>
4
2010-02-17T07:11:26Z
[ "python" ]
what is the usefulness of '>' in python
2,278,901
<pre><code>print 'xxx' &gt; 'ssaww' </code></pre> <p>it print 'true'</p> <p>who can give me a clear example .</p> <p>thanks</p>
0
2010-02-17T07:10:23Z
2,278,910
<p>Just like in math, <code>&gt;</code> compares two operands and returns True if the left operand is greater than the right, otherwise False.</p>
5
2010-02-17T07:12:08Z
[ "python" ]
what is the usefulness of '>' in python
2,278,901
<pre><code>print 'xxx' &gt; 'ssaww' </code></pre> <p>it print 'true'</p> <p>who can give me a clear example .</p> <p>thanks</p>
0
2010-02-17T07:10:23Z
2,278,917
<p>you can test it out on the interpreter</p> <pre><code>&gt;&gt;&gt; 'xxx'&gt;'yyy' #first character 'x' is less than first character 'y', so false False &gt;&gt;&gt; 'xxx'&gt;'xyy' False &gt;&gt;&gt; 'xyy'&gt;'xyx' #3rd character 'y' is greater than 3rd character 'x', so true True </code></pre>
3
2010-02-17T07:13:38Z
[ "python" ]
what is the usefulness of '>' in python
2,278,901
<pre><code>print 'xxx' &gt; 'ssaww' </code></pre> <p>it print 'true'</p> <p>who can give me a clear example .</p> <p>thanks</p>
0
2010-02-17T07:10:23Z
2,278,950
<p>It can do y>x>z as a nicer way to say y>x and x>z.</p> <p>As others have mentioned its a simple greater-than comparison (in your case for strings).</p>
0
2010-02-17T07:22:19Z
[ "python" ]
Inheritance in Python
2,278,955
<p>We just started learning about class inheritance and attribute lookup in python. I have a question about the following code:</p> <pre><code>class a : n = 1 class b : n = 2 class c : n = 3 class d (a,b) : pass class e (d,c) : pass </code></pre> <p>I know that e.n would equal 1 due to the nature of attribute lookup ...
3
2010-02-17T07:23:22Z
2,278,975
<p>You can't get there from here. Class attributes are replaced. Use the class reference directly (<code>c.n</code>).</p>
1
2010-02-17T07:27:58Z
[ "python", "inheritance", "attributes" ]
Inheritance in Python
2,278,955
<p>We just started learning about class inheritance and attribute lookup in python. I have a question about the following code:</p> <pre><code>class a : n = 1 class b : n = 2 class c : n = 3 class d (a,b) : pass class e (d,c) : pass </code></pre> <p>I know that e.n would equal 1 due to the nature of attribute lookup ...
3
2010-02-17T07:23:22Z
2,279,112
<pre><code>&gt;&gt;&gt; e.__bases__[1].n 3 </code></pre>
1
2010-02-17T07:57:34Z
[ "python", "inheritance", "attributes" ]
Error in downloading and saving image using python
2,278,982
<p>I written a code for downloading and saving images from a site .It worked nicely,but for some urls it is being showing an error.I have paste code below</p> <pre><code>import urllib2 import webbrowser imageurl='http://www.example.com/'+image[s] opener1 = urllib2.build_opener() page1=opener1.open(imageurl) my_pictur...
0
2010-02-17T07:29:25Z
2,279,093
<p>You should fix the link. Try this:</p> <pre><code>&gt;&gt;&gt; import urllib &gt;&gt;&gt; urllib.quote("images/PG013001 GROUP 2.jpg") 'images/PG013001%20GROUP%202.jpg' </code></pre>
1
2010-02-17T07:52:47Z
[ "python" ]
Error in downloading and saving image using python
2,278,982
<p>I written a code for downloading and saving images from a site .It worked nicely,but for some urls it is being showing an error.I have paste code below</p> <pre><code>import urllib2 import webbrowser imageurl='http://www.example.com/'+image[s] opener1 = urllib2.build_opener() page1=opener1.open(imageurl) my_pictur...
0
2010-02-17T07:29:25Z
2,279,212
<p>Urls can't include spaces directly; it's simply not allowed. What you want to do is to quote, or encode the spaces in the filename, so that the url becomes legal. <a href="http://en.wikipedia.org/wiki/Percent-encoding" rel="nofollow">Here's wikipedia on the matter.</a></p> <p>So, you want to quote the urls that y...
1
2010-02-17T08:27:08Z
[ "python" ]
pycurl install :( already have min. libcurl version
2,279,014
<p>I'm running python 2.6 on an Intel Mac OS X 10.5</p> <p>I'm trying to install pycurl 7.16.2.1 (as recommended here <a href="http://curl.haxx.se/mail/curlpython-2009-03/0009.html" rel="nofollow">http://curl.haxx.se/mail/curlpython-2009-03/0009.html</a>), but for some reason, the installation sees my libcurl 7.16.3, ...
3
2010-02-17T07:38:01Z
2,279,353
<p>If you are using the python.org Python 2.6, it is built using the 10.4 SDK so as to be able to run on multiple versions of OS X. In that case, the pycurl build is likely trying to link against the 10.4 version of libcurl, which appears to be 7.13.1. The thread you link to is talking about using the 10.5 Apple-supp...
7
2010-02-17T08:57:44Z
[ "python", "osx", "libcurl", "pycurl" ]
pycurl install :( already have min. libcurl version
2,279,014
<p>I'm running python 2.6 on an Intel Mac OS X 10.5</p> <p>I'm trying to install pycurl 7.16.2.1 (as recommended here <a href="http://curl.haxx.se/mail/curlpython-2009-03/0009.html" rel="nofollow">http://curl.haxx.se/mail/curlpython-2009-03/0009.html</a>), but for some reason, the installation sees my libcurl 7.16.3, ...
3
2010-02-17T07:38:01Z
2,299,115
<p>I got my pycurl from Sourceforge. Seems they'd have installable builds backwards and forwards that would match any "shipped with" Mac OS X configuration there is. I believe the URL is <a href="http://pycurl.sourceforge.net" rel="nofollow">http://pycurl.sourceforge.net</a> but don't quote me on that.</p> <p>BZT</p>
0
2010-02-19T19:46:43Z
[ "python", "osx", "libcurl", "pycurl" ]