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
Google App Engine proxy
1,681,806
<p>What would be the simplest implementation of a proxy written for GAE, which relays every URL (including POST, and header data) to a remote HTTP host, and return with it's result (with special consideration to error codes)? Please apply KISS principles!</p>
3
2009-11-05T16:32:27Z
10,678,979
<p>Downy, did not work with ajax/GAS. Use <a href="http://code.google.com/p/bs2grproxy/" rel="nofollow">http://code.google.com/p/bs2grproxy/</a> BS2 GAE Reverse Proxy. I used it, with ajax (GAS), works fine. </p>
1
2012-05-21T02:45:22Z
[ "python", "google-app-engine", "proxy" ]
How to debug a MemoryError in Python? Tools for tracking memory use?
1,681,836
<p>I have a Python program that dies with a MemoryError when I feed it a large file. Are there any tools that I could use to figure out what's using the memory?</p> <p>This program ran fine on smaller input files. The program obviously needs some scalability improvements; I'm just trying to figure out where. "Bench...
10
2009-11-05T16:36:26Z
1,681,869
<p><a href="http://guppy-pe.sourceforge.net/#Heapy">Heapy</a> is a memory profiler for Python, which is the type of tool you need.</p>
9
2009-11-05T16:39:43Z
[ "python", "memory-management", "profiling", "out-of-memory" ]
How to debug a MemoryError in Python? Tools for tracking memory use?
1,681,836
<p>I have a Python program that dies with a MemoryError when I feed it a large file. Are there any tools that I could use to figure out what's using the memory?</p> <p>This program ran fine on smaller input files. The program obviously needs some scalability improvements; I'm just trying to figure out where. "Bench...
10
2009-11-05T16:36:26Z
1,681,971
<p>The simplest and lightweight way would likely be to use the <a href="http://blog.doughellmann.com/2009/10/pymotw-sys-part-3-memory-management-and.html" rel="nofollow">built in memory query capabilities</a> of Python, such as <code>sys.getsizeof</code> - just run it on your objects for a reduced problem (i.e. a small...
3
2009-11-05T16:51:25Z
[ "python", "memory-management", "profiling", "out-of-memory" ]
How to debug a MemoryError in Python? Tools for tracking memory use?
1,681,836
<p>I have a Python program that dies with a MemoryError when I feed it a large file. Are there any tools that I could use to figure out what's using the memory?</p> <p>This program ran fine on smaller input files. The program obviously needs some scalability improvements; I'm just trying to figure out where. "Bench...
10
2009-11-05T16:36:26Z
1,697,758
<p>In your case, the answer is probably very simple: Do not read the whole file at once but process the file chunk by chunk. That may be very easy or complicated depending on your usage scenario. Just for example, a MD5 checksum computation can be done much more efficiently for huge files without reading the whole file...
2
2009-11-08T20:09:03Z
[ "python", "memory-management", "profiling", "out-of-memory" ]
How to debug a MemoryError in Python? Tools for tracking memory use?
1,681,836
<p>I have a Python program that dies with a MemoryError when I feed it a large file. Are there any tools that I could use to figure out what's using the memory?</p> <p>This program ran fine on smaller input files. The program obviously needs some scalability improvements; I'm just trying to figure out where. "Bench...
10
2009-11-05T16:36:26Z
2,209,214
<p>You asked for a tool recommendation:</p> <p>Python Memory Validator allows you to monitor the memory usage, allocation locations, GC collections, object instances, memory snapshots, etc of your Python application. Windows only.</p> <p><a href="http://www.softwareverify.com/python/memory/index.html" rel="nofollow">...
1
2010-02-05T17:53:34Z
[ "python", "memory-management", "profiling", "out-of-memory" ]
Django Formsets - form.is_valid() is False preventing formset validation
1,682,069
<p>I'm am utilizing a formset to enable users subscribe to multiple feeds. I require a) Users chose a subscription by selecting a boolean field, and are also required to tag the subscription and b) a user must subscribe to an specified number of subscriptions.</p> <p>Currently the below code is capable of a) ensuring ...
0
2009-11-05T17:03:49Z
1,682,342
<p>I made attempt to circumvent my problem...it is <em>not</em> a good solution, it's very much so a hack. It allows people to proceed if they subscribe to the required number of feeds (in the case below more than 1), however if less than the required number of feeds, it fails to show the error message raised.</p> <pr...
0
2009-11-05T17:48:18Z
[ "python", "django", "django-forms" ]
Django Formsets - form.is_valid() is False preventing formset validation
1,682,069
<p>I'm am utilizing a formset to enable users subscribe to multiple feeds. I require a) Users chose a subscription by selecting a boolean field, and are also required to tag the subscription and b) a user must subscribe to an specified number of subscriptions.</p> <p>Currently the below code is capable of a) ensuring ...
0
2009-11-05T17:03:49Z
1,688,005
<p>Solved. Below is a quick run through of the solution.</p> <p>Reporting the error required manipulating and formating a special error message. In the source code for formsets I found the errors that apply to a whole form are known as *non_form_errors* and produced a custom error based on this. [note: I couldn't find...
2
2009-11-06T14:37:21Z
[ "python", "django", "django-forms" ]
Cross-platform way to terminate a process in python
1,682,447
<p>When I try to kill a process in windows with the subprocess.Popen.terminate() or kill() commands, I get an access denied error. I really need a cross-platform way to terminate the process if the file no longer exists (Yes, I know it's not the most elegant way of doing what I'm doing), I don't want to have to use pl...
0
2009-11-05T18:06:03Z
1,682,509
<p>You can easily make a platform independent call by doing something trivial like:</p> <pre><code>try: import win32 def kill(param): # the code from S.Lotts link except ImportError: def kill(param): # the unix way </code></pre> <p>Why this doesn't exist in python by default I don't know, but th...
2
2009-11-05T18:15:58Z
[ "python", "terminate" ]
How to write a stub for a classmethod in Python
1,682,504
<p>I have a method which calls for a classmethod of another class</p> <pre><code>def get_interface_params_by_mac(self, host, mac_unified): lines = RemoteCommand.remote_command(host, cls.IFCONFIG) </code></pre> <p>...</p> <pre><code>class RemoteCommand(object): @classmethod def remote_command(cls, ho...
0
2009-11-05T18:15:34Z
1,682,651
<p>Your unit-test code (maybe in its <code>setUp</code> method, if this is needed across several test methods and thus qualifies as a fixture) should do:</p> <pre><code>def fake_command(cls, host, cmd, sh=None): pass # whatever you want in here self.save_remote_command = somemodule.RemoteCommand.remote_command some...
6
2009-11-05T18:37:35Z
[ "python", "unit-testing" ]
Sorting Lists of List of Dictionaries
1,682,506
<p>I've just read in a file that is something like:</p> <pre><code>name: john, jane car: db9, m5 food: pizza, lasagne </code></pre> <p>Each of these rows (names, car, food) are in order of who owns what. Therefore John owns the car 'DB9' and his favourite food is 'Pizza'. Likewise with Jane, her car is an 'M5' and he...
0
2009-11-05T18:15:49Z
1,682,578
<p>Try:</p> <pre><code>f = open('filename.txt') result = [] for line in f: key, values = line.split(':') values = values.rstrip().split(', ') for i, value in enumerate(values): try: result[i][key] = value except IndexError: result.append({ key: value}) print result...
1
2009-11-05T18:26:02Z
[ "python", "list", "sorting", "dictionary" ]
Sorting Lists of List of Dictionaries
1,682,506
<p>I've just read in a file that is something like:</p> <pre><code>name: john, jane car: db9, m5 food: pizza, lasagne </code></pre> <p>Each of these rows (names, car, food) are in order of who owns what. Therefore John owns the car 'DB9' and his favourite food is 'Pizza'. Likewise with Jane, her car is an 'M5' and he...
0
2009-11-05T18:15:49Z
1,682,585
<p>Looks like you want something like:</p> <pre><code>import collections data = '''name: john, jane car: db9, m5 food: pizza, lasagne ''' personal_list = collections.defaultdict(dict) for line in data.splitlines(): key, _, info = line.partition(':') infos = info.split(',') key = key.strip().title() for i, i...
3
2009-11-05T18:26:38Z
[ "python", "list", "sorting", "dictionary" ]
Sorting Lists of List of Dictionaries
1,682,506
<p>I've just read in a file that is something like:</p> <pre><code>name: john, jane car: db9, m5 food: pizza, lasagne </code></pre> <p>Each of these rows (names, car, food) are in order of who owns what. Therefore John owns the car 'DB9' and his favourite food is 'Pizza'. Likewise with Jane, her car is an 'M5' and he...
0
2009-11-05T18:15:49Z
1,682,893
<p>Split the initial data into index/key/value triples go from there.</p> <pre><code>def parse_data(lines): for line in lines: key, _, data = line.partition(':') for i, datum in enumerate(x.strip() for x in data.split(',')): yield i, key, datum </code></pre> <p>From there you can aggre...
1
2009-11-05T19:15:17Z
[ "python", "list", "sorting", "dictionary" ]
Sorting Lists of List of Dictionaries
1,682,506
<p>I've just read in a file that is something like:</p> <pre><code>name: john, jane car: db9, m5 food: pizza, lasagne </code></pre> <p>Each of these rows (names, car, food) are in order of who owns what. Therefore John owns the car 'DB9' and his favourite food is 'Pizza'. Likewise with Jane, her car is an 'M5' and he...
0
2009-11-05T18:15:49Z
1,683,122
<p>An homage to generators:</p> <pre><code>#!/usr/bin/env python data=(zip(*([elt.strip().title() for elt in line.replace(':',',',1).split(',')] for line in open('filename.txt','r')))) personal_list=[dict(zip(data[0],datum)) for datum in data[1:]] print(personal_list) # [{'Food': 'Pizza', 'Car': 'Db9', 'N...
1
2009-11-05T19:55:19Z
[ "python", "list", "sorting", "dictionary" ]
How non blocking read/write throught remote FileSystem
1,682,515
<p>Is there a way to write and read files on a remote filesystem (such as NFS, SSHFS, or sambafs) in a way that read or write or even open return immediately with an error code? In fact I'm using Twisted and I want to know whether there is a safe way to access remote files without blocking my reactor.</p>
5
2009-11-05T18:16:57Z
1,682,669
<p>In Twisted, for remote filesystems just like for any other blocking calls, you can use <a href="http://blog.ianbicking.org/twisted-and-threads.html">threads.deferToThread</a> -- a reasonably elegant way to deal with pesky blocking syscalls!-)</p>
7
2009-11-05T18:40:50Z
[ "python", "networking", "filesystems", "twisted" ]
How non blocking read/write throught remote FileSystem
1,682,515
<p>Is there a way to write and read files on a remote filesystem (such as NFS, SSHFS, or sambafs) in a way that read or write or even open return immediately with an error code? In fact I'm using Twisted and I want to know whether there is a safe way to access remote files without blocking my reactor.</p>
5
2009-11-05T18:16:57Z
1,720,930
<p>This is actually very similar to my question asked <a href="http://stackoverflow.com/questions/1720816/non-blocking-file-access-with-twisted">here</a>. It seems that the only way to get around the limitations of the operating system, at present, is to use threads or external processes to handle your file IO for you....
1
2009-11-12T09:12:37Z
[ "python", "networking", "filesystems", "twisted" ]
Django: Blank Choices in Many To Many Fields
1,682,537
<p>When making forms in Django, the IntegerField comes with a blank choice (a bunch of dashes "------") if called with blank=True and null=True. Is there any way to get ManyToManyField to include such an explicit blank choice?</p> <p>I've tried subclassing ManyToManyField with no success:</p> <pre><code>class ManyFi...
0
2009-11-05T18:19:51Z
1,682,956
<p>That is not really an improvement on the interface, IMO.</p> <p>Why not have a button in your template saying "none of these" or "reset choices"? Better yet - if your field is called "Blah" make the button say "Unselect all Blah".</p> <p>The button would just have some javascript to clear out any selection in the ...
4
2009-11-05T19:28:18Z
[ "python", "django" ]
Why does Python's list.append evaluate to false?
1,682,567
<p>Is there a reason being <code>list.append</code> evaluating to false? Or is it just the C convention of returning 0 when successful that comes into play?</p> <pre><code>&gt;&gt;&gt; u = [] &gt;&gt;&gt; not u.append(6) True </code></pre>
16
2009-11-05T18:24:09Z
1,682,572
<p><code>None</code> evaluates to <code>False</code> and in python a function that does not return anything is assumed to have returned <code>None</code>.</p> <p>If you type:</p> <pre><code>&gt;&gt; print u.append(6) None </code></pre> <p>Tadaaam :)</p>
16
2009-11-05T18:25:20Z
[ "python" ]
Why does Python's list.append evaluate to false?
1,682,567
<p>Is there a reason being <code>list.append</code> evaluating to false? Or is it just the C convention of returning 0 when successful that comes into play?</p> <pre><code>&gt;&gt;&gt; u = [] &gt;&gt;&gt; not u.append(6) True </code></pre>
16
2009-11-05T18:24:09Z
1,682,573
<p>It modifies the list in-place, and returns <code>None</code>. <code>None</code> evaluates to false.</p>
5
2009-11-05T18:25:28Z
[ "python" ]
Why does Python's list.append evaluate to false?
1,682,567
<p>Is there a reason being <code>list.append</code> evaluating to false? Or is it just the C convention of returning 0 when successful that comes into play?</p> <pre><code>&gt;&gt;&gt; u = [] &gt;&gt;&gt; not u.append(6) True </code></pre>
16
2009-11-05T18:24:09Z
1,682,574
<p>because <code>.append</code> method returns <code>None</code>, therefore <code>not None</code> evaluates to <code>True</code>. Python on error usually raises an error:</p> <pre><code>&gt;&gt;&gt; a = () &gt;&gt;&gt; a.append(5) Traceback (most recent call last): File "&lt;pyshell#1&gt;", line 1, in &lt;module&gt;...
4
2009-11-05T18:25:40Z
[ "python" ]
Why does Python's list.append evaluate to false?
1,682,567
<p>Is there a reason being <code>list.append</code> evaluating to false? Or is it just the C convention of returning 0 when successful that comes into play?</p> <pre><code>&gt;&gt;&gt; u = [] &gt;&gt;&gt; not u.append(6) True </code></pre>
16
2009-11-05T18:24:09Z
1,682,598
<p>Actually, it returns <code>None</code></p> <pre> <code> >>> print u.append(6) None >>> print not None True >>> </code> </pre>
2
2009-11-05T18:29:13Z
[ "python" ]
Why does Python's list.append evaluate to false?
1,682,567
<p>Is there a reason being <code>list.append</code> evaluating to false? Or is it just the C convention of returning 0 when successful that comes into play?</p> <pre><code>&gt;&gt;&gt; u = [] &gt;&gt;&gt; not u.append(6) True </code></pre>
16
2009-11-05T18:24:09Z
1,682,601
<p>Most Python methods that mutate a container in-place return <code>None</code> -- an application of the principle of <a href="http://en.wikipedia.org/wiki/Command-query%5Fseparation">Command-query separation</a>. (Python's always reasonably pragmatic about things, so a few mutators do return a usable value when gett...
27
2009-11-05T18:29:40Z
[ "python" ]
What are cycles ? in relation to python
1,682,657
<p>im using the fantastic <a href="http://eric-ide.python-projects.org/" rel="nofollow">eric4</a> ide to code python, it's got a tool built in called 'cyclops', which is apparently looking for cycles. After running it, it gives me a bunch of big bold red letters declaring there to be a multitude of cycles in my code. T...
4
2009-11-05T18:38:08Z
1,682,698
<p>All Cyclops tells you is whether there are objects in your code that refer to themselves through a chain of other objects. This used to be an issue in python, because the garbage collector wouldn't handle these kinds of objects correctly. That problem has since been, for the most part, fixed.</p> <p>Bottom line: if...
1
2009-11-05T18:44:01Z
[ "python", "cycle" ]
What are cycles ? in relation to python
1,682,657
<p>im using the fantastic <a href="http://eric-ide.python-projects.org/" rel="nofollow">eric4</a> ide to code python, it's got a tool built in called 'cyclops', which is apparently looking for cycles. After running it, it gives me a bunch of big bold red letters declaring there to be a multitude of cycles in my code. T...
4
2009-11-05T18:38:08Z
1,682,712
<p>A cycle (or "references loop") is two or more objects referring to each other, e.g.:</p> <pre><code>alist = [] anoth = [alist] alist.append(anoth) </code></pre> <p>or</p> <pre><code>class Child(object): pass class Parent(object): pass c = Child() p = Parent() c.parent = p p.child = c </code></pre> <p>Of course...
4
2009-11-05T18:46:39Z
[ "python", "cycle" ]
Embedding Python Design
1,682,831
<p>There are lots of tutorials/instructions on how to embed python in an application, but nothing (that I've seen) on overall design for how the embedded interpreter should be used and interact with the application.</p> <p>The only idea I could think of would be to simply give the user a method (menu option, etc) of e...
2
2009-11-05T19:03:12Z
1,682,872
<p><strong>The only idea I could think of would be to simply give the user a method (menu option, etc) of executing scripts in the program.</strong></p> <p>Correct.</p> <p><strong>So certain classes, functions, objects, etc. would be exported to python, some script would do something, then said script could be run fr...
1
2009-11-05T19:11:51Z
[ "python", "design", "embedding" ]
What does the ** maths operator do in Python?
1,683,008
<p>What does this mean in Python:</p> <pre><code>sock.recvfrom(2**16) </code></pre> <p>I know what sock is, and I get the gist of the <code>recvfrom</code> function, but what the heck is <code>2**16</code>? Specifically, the two asterisk/double asterisk operator?</p> <hr> <p><em>(english keywords, because it's hard...
11
2009-11-05T19:38:42Z
1,683,024
<p>It is the power operator, see this reference:</p> <p><a href="http://www.webreference.com/programming/python/">http://www.webreference.com/programming/python/</a></p> <p>It is equivalent to 2<sup>16</sup> = 65536</p>
26
2009-11-05T19:40:20Z
[ "python", "syntax", "operators" ]
What does the ** maths operator do in Python?
1,683,008
<p>What does this mean in Python:</p> <pre><code>sock.recvfrom(2**16) </code></pre> <p>I know what sock is, and I get the gist of the <code>recvfrom</code> function, but what the heck is <code>2**16</code>? Specifically, the two asterisk/double asterisk operator?</p> <hr> <p><em>(english keywords, because it's hard...
11
2009-11-05T19:38:42Z
1,683,027
<p>2 raised to the 16th power</p>
5
2009-11-05T19:40:47Z
[ "python", "syntax", "operators" ]
What does the ** maths operator do in Python?
1,683,008
<p>What does this mean in Python:</p> <pre><code>sock.recvfrom(2**16) </code></pre> <p>I know what sock is, and I get the gist of the <code>recvfrom</code> function, but what the heck is <code>2**16</code>? Specifically, the two asterisk/double asterisk operator?</p> <hr> <p><em>(english keywords, because it's hard...
11
2009-11-05T19:38:42Z
1,683,038
<p>I believe that's the <a href="http://docs.python.org/reference/expressions.html#the-power-operator" rel="nofollow" title="power operator">power operator</a>, such that <code>2**5</code> = 32.</p>
3
2009-11-05T19:42:11Z
[ "python", "syntax", "operators" ]
What does the ** maths operator do in Python?
1,683,008
<p>What does this mean in Python:</p> <pre><code>sock.recvfrom(2**16) </code></pre> <p>I know what sock is, and I get the gist of the <code>recvfrom</code> function, but what the heck is <code>2**16</code>? Specifically, the two asterisk/double asterisk operator?</p> <hr> <p><em>(english keywords, because it's hard...
11
2009-11-05T19:38:42Z
1,683,759
<p>It is the awesome <a href="http://docs.python.org/reference/expressions.html#the-power-operator" rel="nofollow">power operator</a> which like <a href="http://docs.python.org/library/functions.html#complex" rel="nofollow">complex numbers</a> is another thing you wonder why more programming languages don't have.</p>
1
2009-11-05T21:28:28Z
[ "python", "syntax", "operators" ]
What does the ** maths operator do in Python?
1,683,008
<p>What does this mean in Python:</p> <pre><code>sock.recvfrom(2**16) </code></pre> <p>I know what sock is, and I get the gist of the <code>recvfrom</code> function, but what the heck is <code>2**16</code>? Specifically, the two asterisk/double asterisk operator?</p> <hr> <p><em>(english keywords, because it's hard...
11
2009-11-05T19:38:42Z
1,683,781
<p><a href="http://docs.python.org/library/operator.html#mapping-operators-to-functions">http://docs.python.org/library/operator.html#mapping-operators-to-functions</a></p> <pre><code>a ** b = pow(a,b) </code></pre>
6
2009-11-05T21:31:37Z
[ "python", "syntax", "operators" ]
Alternative to PycURL?
1,683,103
<p>Here's a bit of code that is uploading a file:</p> <pre><code> file_size = os.path.getsize('Tea.rdf') f = file('Tea.rdf') c = pycurl.Curl() c.setopt(pycurl.URL, 'http://localhost:8080/openrdf-sesame/repositories/rep/statements') c.setopt(pycurl.HTTPHEADER, ["Content-Type: application/rdf+xml;charset=UTF-8"...
2
2009-11-05T19:52:57Z
1,683,405
<p>Using <a href="http://code.google.com/p/httplib2/" rel="nofollow">httplib2</a>:</p> <pre><code>import httplib2 http = httplib2.Http() f = open('Tea.rdf') body = f.read() url = 'http://localhost:8080/openrdf-sesame/repositories/rep/statements' headers = {'Content-type': 'application/rdf+xml;charset=utf-8'} resp, co...
1
2009-11-05T20:36:16Z
[ "python", "pycurl" ]
Alternative to PycURL?
1,683,103
<p>Here's a bit of code that is uploading a file:</p> <pre><code> file_size = os.path.getsize('Tea.rdf') f = file('Tea.rdf') c = pycurl.Curl() c.setopt(pycurl.URL, 'http://localhost:8080/openrdf-sesame/repositories/rep/statements') c.setopt(pycurl.HTTPHEADER, ["Content-Type: application/rdf+xml;charset=UTF-8"...
2
2009-11-05T19:52:57Z
6,460,414
<p>your example converted to httplib:</p> <pre><code>import httplib host = 'localhost:8080' path = '/openrdf-sesame/repositories/rep/statements' path = '/index.html' headers = {'Content-type': 'application/rdf+xml;charset=utf-8'} f = open('Tea.rdf') conn = httplib.HTTPConnection(host) conn.request('PUT', path, f, he...
0
2011-06-23T20:46:20Z
[ "python", "pycurl" ]
Alternative to PycURL?
1,683,103
<p>Here's a bit of code that is uploading a file:</p> <pre><code> file_size = os.path.getsize('Tea.rdf') f = file('Tea.rdf') c = pycurl.Curl() c.setopt(pycurl.URL, 'http://localhost:8080/openrdf-sesame/repositories/rep/statements') c.setopt(pycurl.HTTPHEADER, ["Content-Type: application/rdf+xml;charset=UTF-8"...
2
2009-11-05T19:52:57Z
7,345,197
<p>Yes, pycurl have a bad API design, cURL is powerful. It have more futures, then urllib/urllib2.</p> <p>Maybe you want to try to use human_curl. It's python curl wrapper. You can install it from sources <a href="https://github.com/lispython/human_curl" rel="nofollow">https://github.com/lispython/human_curl</a> or by...
4
2011-09-08T08:27:21Z
[ "python", "pycurl" ]
Django: Streaming dynamically generated XML output through an HttpResponse
1,683,144
<p>recently I wanted to return through a Django view a dynamically generated XML tree. The module I use for XML manipulation is the usual cElementTree.</p> <p>I think I tackled what I wanted by doing the following:</p> <pre><code>def view1(request): resp = HttpResponse(g()) return resp def g(): root = E...
4
2009-11-05T19:58:30Z
1,683,218
<p>Does it work? If it doesn't work, what error does it throw? </p> <p>If you're building a full-blown API for a django site, take a look at django-piston. It takes care of a lot of the busywork related to that.</p> <p><a href="http://bitbucket.org/jespern/django-piston/wiki/Home" rel="nofollow">http://bitbucket.org/...
2
2009-11-05T20:08:06Z
[ "python", "xml", "django" ]
Django: Streaming dynamically generated XML output through an HttpResponse
1,683,144
<p>recently I wanted to return through a Django view a dynamically generated XML tree. The module I use for XML manipulation is the usual cElementTree.</p> <p>I think I tackled what I wanted by doing the following:</p> <pre><code>def view1(request): resp = HttpResponse(g()) return resp def g(): root = E...
4
2009-11-05T19:58:30Z
1,683,360
<p>Yes, it's perfectly legitimate to return an iterator in an HttpResponse. As you've discovered, that allows you to stream content to the client.</p>
2
2009-11-05T20:26:58Z
[ "python", "xml", "django" ]
Django: Streaming dynamically generated XML output through an HttpResponse
1,683,144
<p>recently I wanted to return through a Django view a dynamically generated XML tree. The module I use for XML manipulation is the usual cElementTree.</p> <p>I think I tackled what I wanted by doing the following:</p> <pre><code>def view1(request): resp = HttpResponse(g()) return resp def g(): root = E...
4
2009-11-05T19:58:30Z
1,683,676
<p>Yes. That's THE WAY you do it on Django.</p>
2
2009-11-05T21:16:52Z
[ "python", "xml", "django" ]
Django: Streaming dynamically generated XML output through an HttpResponse
1,683,144
<p>recently I wanted to return through a Django view a dynamically generated XML tree. The module I use for XML manipulation is the usual cElementTree.</p> <p>I think I tackled what I wanted by doing the following:</p> <pre><code>def view1(request): resp = HttpResponse(g()) return resp def g(): root = E...
4
2009-11-05T19:58:30Z
1,684,265
<p>About middlewares "breaking" streaming:</p> <p>CommonMiddleware will try to consume the whole iterator <em>if</em> you set <code>USE_ETAGS = True</code> in settings. But in modern Django (1.1) there's a better way to do conditional get than CommonMiddleware + ConditionalGetMiddleware -- <a href="http://docs.djangop...
11
2009-11-05T23:01:03Z
[ "python", "xml", "django" ]
website load testing Python script
1,683,342
<p>I am after a Python script to help me load test my Google App Engine website. I want to give it a set of URLs and a request rate (would need to use threads) and then measure the response times of my website.</p> <p>I have had a look at a few solutions but they don't let you set an upper limit for the request rate.<...
0
2009-11-05T20:23:57Z
1,683,359
<p>You don't need a python script for this, you want to use the apache tool <code>ab</code>.</p> <p><a href="http://httpd.apache.org/docs/2.0/programs/ab.html" rel="nofollow">http://httpd.apache.org/docs/2.0/programs/ab.html</a></p> <p>It is the canonical load testing solution, and will get you great metrics for perf...
3
2009-11-05T20:26:45Z
[ "python", "google-app-engine", "website", "load-testing" ]
website load testing Python script
1,683,342
<p>I am after a Python script to help me load test my Google App Engine website. I want to give it a set of URLs and a request rate (would need to use threads) and then measure the response times of my website.</p> <p>I have had a look at a few solutions but they don't let you set an upper limit for the request rate.<...
0
2009-11-05T20:23:57Z
1,683,573
<p><a href="http://www.pylot.org/" rel="nofollow">Pylot</a> is a versatile load testing tool written in Python. I haven't used it personally, but it seems good.</p>
3
2009-11-05T21:01:01Z
[ "python", "google-app-engine", "website", "load-testing" ]
'getattr(): attribute name must be string' error in admin panel for a model with an ImageField
1,683,362
<p>I have the following model set up:</p> <pre><code>class UserProfile(models.Model): "Additional attributes for users." url = models.URLField() location = models.CharField(max_length=100) user = models.ForeignKey(User, unique=True) avatar = models.ImageField(upload_to='/home/something/www/avatars'...
3
2009-11-05T20:27:17Z
1,683,546
<p>The problem is probably this: </p> <pre><code>height_field=80, width_field=80 </code></pre> <p><code>height_field</code> and <code>width_field</code>, if you use them, are supposed to be names of fields on the model which contain the height and width information. Fix this it should work.</p>
5
2009-11-05T20:57:18Z
[ "python", "django", "django-models", "django-admin" ]
'getattr(): attribute name must be string' error in admin panel for a model with an ImageField
1,683,362
<p>I have the following model set up:</p> <pre><code>class UserProfile(models.Model): "Additional attributes for users." url = models.URLField() location = models.CharField(max_length=100) user = models.ForeignKey(User, unique=True) avatar = models.ImageField(upload_to='/home/something/www/avatars'...
3
2009-11-05T20:27:17Z
1,683,591
<p>Your problem is with <code>height_field=80</code> and <code>width_field=80</code> these should not contain the height and width you require but rather the names of fields in your model that can have the values for height and width save in them.</p> <p>As explained in the Django documentation for the <a href="http:/...
11
2009-11-05T21:03:41Z
[ "python", "django", "django-models", "django-admin" ]
Python .pyc files removal in django app
1,683,695
<p>i have a following solution structure in python:</p> <pre><code>main_app main_app/template_processor/ main_app/template_processor/models main_app/template_processor/views </code></pre> <p>everything works just fine on my local machine. as soon as code gets to server (it stopped working after i removed all .pyc fil...
0
2009-11-05T21:20:09Z
1,683,975
<p>Sounds like Django isn't seeing that module (folder, in this case) for some reason. Make sure all the folders have a file called <code>__init__.py</code> (notice the two underscores before and after). Once that's done, make sure it's listed in your installed apps.</p> <p>Maybe you made some change to it that's caus...
1
2009-11-05T22:07:15Z
[ "python", "django", "django-models" ]
Python .pyc files removal in django app
1,683,695
<p>i have a following solution structure in python:</p> <pre><code>main_app main_app/template_processor/ main_app/template_processor/models main_app/template_processor/views </code></pre> <p>everything works just fine on my local machine. as soon as code gets to server (it stopped working after i removed all .pyc fil...
0
2009-11-05T21:20:09Z
1,684,175
<p>Hm, looking at your directory structure, I think that you need to import all your models in <code>template_processor/models/__init__.py</code>, because Django looks only in <code>&lt;app_name&gt;.models</code> module when loading models automatically (i.e. for syncdb).</p>
1
2009-11-05T22:42:20Z
[ "python", "django", "django-models" ]
Python .pyc files removal in django app
1,683,695
<p>i have a following solution structure in python:</p> <pre><code>main_app main_app/template_processor/ main_app/template_processor/models main_app/template_processor/views </code></pre> <p>everything works just fine on my local machine. as soon as code gets to server (it stopped working after i removed all .pyc fil...
0
2009-11-05T21:20:09Z
1,684,227
<p>My guess would be that you renamed a file, and didn't delete the oldname.pyc file.</p> <p>So if you try to import oldname</p> <p>then you rename oldname to rename, but don't update your import statement, the code will work on systems where oldname.pyc exists, however python won't be able to recreate oldname.pyc i...
1
2009-11-05T22:52:49Z
[ "python", "django", "django-models" ]
Python .pyc files removal in django app
1,683,695
<p>i have a following solution structure in python:</p> <pre><code>main_app main_app/template_processor/ main_app/template_processor/models main_app/template_processor/views </code></pre> <p>everything works just fine on my local machine. as soon as code gets to server (it stopped working after i removed all .pyc fil...
0
2009-11-05T21:20:09Z
1,684,547
<p>Ok, if anyone's interested in what really was happening, i've got a story to tell ya: <a href="http://code.djangoproject.com/ticket/4470" rel="nofollow">http://code.djangoproject.com/ticket/4470</a> that's basically what i was going to implement. in order to really get this thing work i still should have a file mode...
0
2009-11-06T00:08:08Z
[ "python", "django", "django-models" ]
What's the easiest way of finding a child instance from a parent instance in Django?
1,683,711
<p>My application uses class inheritance to minimize repetition across my models. My models.py looks kind of like this:</p> <pre><code>class BaseModel(models.Model): title = models.CharField(max_length=100) pub_date = models.DateField() class Child(BaseModel): foo = models.CharField(max_length=20) class Se...
0
2009-11-05T21:22:28Z
1,683,792
<p>I haven't tested this, but it might be worth tinkering with:</p> <pre><code>def get_absolute_url(self): subclasses = ('child', 'secondchild', ) for subclass in subclasses: if hasattr(self, subclass): return getattr(self, subclass).get_absolute_url() return '/base/%i' % self.id </co...
0
2009-11-05T21:33:04Z
[ "python", "django" ]
What's the easiest way of finding a child instance from a parent instance in Django?
1,683,711
<p>My application uses class inheritance to minimize repetition across my models. My models.py looks kind of like this:</p> <pre><code>class BaseModel(models.Model): title = models.CharField(max_length=100) pub_date = models.DateField() class Child(BaseModel): foo = models.CharField(max_length=20) class Se...
0
2009-11-05T21:22:28Z
1,683,798
<p>I haven't messed with Django inheitance much, so I suppose you can't override get_absolute_url() in the model classes? </p> <p>Perhaps the visitor pattern could help if there are lot of functions that need this in many different places.</p>
0
2009-11-05T21:34:14Z
[ "python", "django" ]
What's the easiest way of finding a child instance from a parent instance in Django?
1,683,711
<p>My application uses class inheritance to minimize repetition across my models. My models.py looks kind of like this:</p> <pre><code>class BaseModel(models.Model): title = models.CharField(max_length=100) pub_date = models.DateField() class Child(BaseModel): foo = models.CharField(max_length=20) class Se...
0
2009-11-05T21:22:28Z
1,689,249
<p>Various forms of this question pop up here regularly. <a href="http://stackoverflow.com/questions/929029/how-do-i-access-the-child-classes-of-an-object-in-django-without-knowing-the-name/929982#929982">This answer</a> demonstrates a generic way to "cast" a parent type to its proper subtype without having to query ev...
0
2009-11-06T17:56:15Z
[ "python", "django" ]
Sort a multidimensional list by a variable number of keys
1,683,775
<p>I've read <a href="http://stackoverflow.com/questions/1516249/python-list-sorting-with-multiple-attributes-and-mixed-order">this post</a> and is hasn't ended up working for me.</p> <p><em>Edit: the functionality I'm describing is just like the sorting function in Excel... if that makes it any clearer</em></p> <p>H...
9
2009-11-05T21:30:45Z
1,683,863
<p>This will sort by columns 2 and 3:</p> <pre><code>a.sort(key=operator.itemgetter(2,3)) </code></pre>
7
2009-11-05T21:44:13Z
[ "python", "sorting" ]
Sort a multidimensional list by a variable number of keys
1,683,775
<p>I've read <a href="http://stackoverflow.com/questions/1516249/python-list-sorting-with-multiple-attributes-and-mixed-order">this post</a> and is hasn't ended up working for me.</p> <p><em>Edit: the functionality I'm describing is just like the sorting function in Excel... if that makes it any clearer</em></p> <p>H...
9
2009-11-05T21:30:45Z
1,683,868
<p>Make sure you have converted the numbers to ints, otherwise they will sort alphabetically rather than numerically</p> <pre><code># Sort the list in place def sortByColumn(A,*args): import operator A.sort(key=operator.itemgetter(*args)) return A </code></pre> <p>or </p> <pre><code># Leave the original ...
1
2009-11-05T21:45:02Z
[ "python", "sorting" ]
Sort a multidimensional list by a variable number of keys
1,683,775
<p>I've read <a href="http://stackoverflow.com/questions/1516249/python-list-sorting-with-multiple-attributes-and-mixed-order">this post</a> and is hasn't ended up working for me.</p> <p><em>Edit: the functionality I'm describing is just like the sorting function in Excel... if that makes it any clearer</em></p> <p>H...
9
2009-11-05T21:30:45Z
1,683,900
<pre><code>import operator: def sortByColumn(bigList, *args) bigList.sort(key=operator.itemgetter(*args)) # sorts the list in place </code></pre>
10
2009-11-05T21:50:02Z
[ "python", "sorting" ]
Sort a multidimensional list by a variable number of keys
1,683,775
<p>I've read <a href="http://stackoverflow.com/questions/1516249/python-list-sorting-with-multiple-attributes-and-mixed-order">this post</a> and is hasn't ended up working for me.</p> <p><em>Edit: the functionality I'm describing is just like the sorting function in Excel... if that makes it any clearer</em></p> <p>H...
9
2009-11-05T21:30:45Z
1,683,903
<p>The key idea here (pun intended) is to use a key function that returns a tuple. Below, the key function is <code>lambda x: (x[idx] for idx in args)</code> <code>x</code> is set to equal an element of aList -- that is, a row of data. It returns a tuple of values, not just one value. The sort() method sorts according ...
2
2009-11-05T21:50:22Z
[ "python", "sorting" ]
Limitations of TEMP directory in Windows?
1,683,831
<p>I have an application written in Python that's writing large amounts of data to the <code>%TEMP%</code> folder. Oddly, every once and awhile, it dies, returning <code>IOError: [Errno 28] No space left on device</code>. The drive has <em>plenty</em> of free space, <code>%TEMP%</code> is not its own partition, I'm a...
4
2009-11-05T21:39:30Z
1,683,853
<p>There shouldn't be such space limitation in Temp. If you wrote the app, I would recommend creating your files in ProgramData...</p>
1
2009-11-05T21:43:01Z
[ "python", "windows", "temporary-files" ]
Limitations of TEMP directory in Windows?
1,683,831
<p>I have an application written in Python that's writing large amounts of data to the <code>%TEMP%</code> folder. Oddly, every once and awhile, it dies, returning <code>IOError: [Errno 28] No space left on device</code>. The drive has <em>plenty</em> of free space, <code>%TEMP%</code> is not its own partition, I'm a...
4
2009-11-05T21:39:30Z
1,683,908
<p>Using a FAT32 filesystem I can imagine this happening when:</p> <ul> <li>Writing a lot of data to one file, and you reach the 4GB file size cap.</li> <li>Or when you are creating a lot of small files and reaching the 2^16-2 files per directory cap.</li> </ul> <p>Apart from this, I don't know of any limitations the...
2
2009-11-05T21:51:33Z
[ "python", "windows", "temporary-files" ]
Limitations of TEMP directory in Windows?
1,683,831
<p>I have an application written in Python that's writing large amounts of data to the <code>%TEMP%</code> folder. Oddly, every once and awhile, it dies, returning <code>IOError: [Errno 28] No space left on device</code>. The drive has <em>plenty</em> of free space, <code>%TEMP%</code> is not its own partition, I'm a...
4
2009-11-05T21:39:30Z
1,683,911
<p>There should be no trouble whatsoever with regard to your %TEMP% directory. </p> <p>What is your disk quota set to for %TEMP%'s hosting volume? Depending in part on what the apps themselves are doing, one of them may be throwing an error due to the disk quota being reached, which is a pain if this quota is set un...
0
2009-11-05T21:52:31Z
[ "python", "windows", "temporary-files" ]
Limitations of TEMP directory in Windows?
1,683,831
<p>I have an application written in Python that's writing large amounts of data to the <code>%TEMP%</code> folder. Oddly, every once and awhile, it dies, returning <code>IOError: [Errno 28] No space left on device</code>. The drive has <em>plenty</em> of free space, <code>%TEMP%</code> is not its own partition, I'm a...
4
2009-11-05T21:39:30Z
1,683,914
<p>What is the exact error you encounter?</p> <p>Are you <a href="http://msdn.microsoft.com/en-us/library/system.io.path.gettempfilename%28VS.80%29.aspx" rel="nofollow">creating too many temp files</a>?</p> <blockquote> <p>The GetTempFileName method will raise an IOException if it is used to create more than <...
7
2009-11-05T21:52:52Z
[ "python", "windows", "temporary-files" ]
org.apache.commons.lang.StringEscapeUtils in python
1,683,965
<p>is there any python module or code that implements the org.apache.commons.lang.StringEscapeUtils.escapeHtml ?</p> <p>exactly the same as in <a href="http://commons.apache.org/lang/api/org/apache/commons/lang/StringEscapeUtils.html#escapeHtml%28java.lang.String%29" rel="nofollow">http://commons.apache.org/lang/api/o...
0
2009-11-05T22:05:55Z
1,684,348
<p>This is for XML and not for HTML, but it might fit your needs: <a href="http://wiki.python.org/moin/EscapingXml" rel="nofollow">Escaping XML</a></p> <pre><code>&gt;&gt;&gt; from xml.sax.saxutils import escape &gt;&gt;&gt; &gt;&gt;&gt; escape("&lt; &amp; &gt;") '&amp;lt; &amp;amp; &amp;gt;' </code></pre>
1
2009-11-05T23:17:35Z
[ "java", "python", "apache", "apache-commons" ]
Is it possible to delete a method from an object (not class) in python?
1,684,099
<p>I have a class with a few methods, some of which are only valid when the object is in a particular state. I would like to have the methods simply not be bound to the objects when they're not in a suitable state, so that I get something like:</p> <pre><code>&gt;&gt;&gt; wiz=Wizard() &gt;&gt;&gt; dir(wiz) ['__doc__',...
5
2009-11-05T22:29:27Z
1,684,183
<p>This isn't directly answering your question, but I think a better approach to solving this problem would be to <strong>not</strong> add/remove the member method <code>domagic</code> on your <code>wiz</code> object:</p> <p>What I would do instead is within the <code>domagic</code> method, add a condition that checks...
9
2009-11-05T22:44:35Z
[ "python" ]
Is it possible to delete a method from an object (not class) in python?
1,684,099
<p>I have a class with a few methods, some of which are only valid when the object is in a particular state. I would like to have the methods simply not be bound to the objects when they're not in a suitable state, so that I get something like:</p> <pre><code>&gt;&gt;&gt; wiz=Wizard() &gt;&gt;&gt; dir(wiz) ['__doc__',...
5
2009-11-05T22:29:27Z
1,684,190
<p>If an object is in a state where calling a given method on that object doesn't make sense, having it disappear from the object's interface seems like the wrong way to handle the problem. More explicit error handling gives you the ability to explain the problem more precisely to your callers, throwing NotEnoughMana ...
6
2009-11-05T22:45:12Z
[ "python" ]
Is it possible to delete a method from an object (not class) in python?
1,684,099
<p>I have a class with a few methods, some of which are only valid when the object is in a particular state. I would like to have the methods simply not be bound to the objects when they're not in a suitable state, so that I get something like:</p> <pre><code>&gt;&gt;&gt; wiz=Wizard() &gt;&gt;&gt; dir(wiz) ['__doc__',...
5
2009-11-05T22:29:27Z
1,684,219
<p>You can use a hack like that:</p> <pre><code>&gt;&gt;&gt; class A(object): ... def test(self): ... print 'test' ... &gt;&gt;&gt; a = A() &gt;&gt;&gt; def noattr(name): ... raise AttributeError('no attribute %s' % name) ... &gt;&gt;&gt; a.test = lambda *a, **k: noattr('test') &gt;&gt;&gt; a.test() ...
2
2009-11-05T22:50:26Z
[ "python" ]
Is it possible to delete a method from an object (not class) in python?
1,684,099
<p>I have a class with a few methods, some of which are only valid when the object is in a particular state. I would like to have the methods simply not be bound to the objects when they're not in a suitable state, so that I get something like:</p> <pre><code>&gt;&gt;&gt; wiz=Wizard() &gt;&gt;&gt; dir(wiz) ['__doc__',...
5
2009-11-05T22:29:27Z
1,684,267
<p>You can't delete a class method from an instance of that class because the instance doesn't <em>have</em> that method. The protocol is: if <code>o</code> is an instance of class <code>Foo</code>, and I call <code>o.bar()</code>, first <code>o</code> is examined to see if it has a method named <code>bar</code>. If...
8
2009-11-05T23:01:14Z
[ "python" ]
Is it possible to delete a method from an object (not class) in python?
1,684,099
<p>I have a class with a few methods, some of which are only valid when the object is in a particular state. I would like to have the methods simply not be bound to the objects when they're not in a suitable state, so that I get something like:</p> <pre><code>&gt;&gt;&gt; wiz=Wizard() &gt;&gt;&gt; dir(wiz) ['__doc__',...
5
2009-11-05T22:29:27Z
1,684,488
<p>Looks like the way to dir() works by default is:</p> <pre><code>dir(obj) == sorted(obj.__dict__.keys() + dir(obj.__class__)) </code></pre> <p>(well, removing duplicates anyway)</p> <p>So an approach would be:</p> <pre><code>class Wizard(object): def __init__(self): self.mana = 0 def __dir__(self...
2
2009-11-05T23:51:51Z
[ "python" ]
Is it possible to delete a method from an object (not class) in python?
1,684,099
<p>I have a class with a few methods, some of which are only valid when the object is in a particular state. I would like to have the methods simply not be bound to the objects when they're not in a suitable state, so that I get something like:</p> <pre><code>&gt;&gt;&gt; wiz=Wizard() &gt;&gt;&gt; dir(wiz) ['__doc__',...
5
2009-11-05T22:29:27Z
1,684,969
<p>There seem to be some pretty good ideas to address the explicit question of how to hide/remove a method from a python object, so I'd like to address a higher level question. </p> <p>Specifically, the problem statement from the original question:</p> <blockquote> <p>I have a class with a few methods, some of w...
1
2009-11-06T02:05:43Z
[ "python" ]
Is it possible to delete a method from an object (not class) in python?
1,684,099
<p>I have a class with a few methods, some of which are only valid when the object is in a particular state. I would like to have the methods simply not be bound to the objects when they're not in a suitable state, so that I get something like:</p> <pre><code>&gt;&gt;&gt; wiz=Wizard() &gt;&gt;&gt; dir(wiz) ['__doc__',...
5
2009-11-05T22:29:27Z
9,537,218
<p>As an additional possibility (twisting the question a little bit), if it makes more sense to only have certain methods on certain instances, you can always add those methods in the <code>__init__</code> of the class to those instances for which it makes sense. Ex: say we have your <code>Wizard</code> class, and the...
1
2012-03-02T16:54:55Z
[ "python" ]
Is it possible to delete a method from an object (not class) in python?
1,684,099
<p>I have a class with a few methods, some of which are only valid when the object is in a particular state. I would like to have the methods simply not be bound to the objects when they're not in a suitable state, so that I get something like:</p> <pre><code>&gt;&gt;&gt; wiz=Wizard() &gt;&gt;&gt; dir(wiz) ['__doc__',...
5
2009-11-05T22:29:27Z
15,821,030
<p>While I agree that this is the wrong solution, my way to "remove" a method would be to overwrite the function with a property that raises an <code>AttributeError</code>. This way <code>hasattr</code> gives the correct result, but it is not as much hassle as using <code>dir</code>.</p>
0
2013-04-04T20:24:49Z
[ "python" ]
BeautifulSoup - extracting attribute values
1,684,120
<p>If Beautiful Soup gives me an anchor tag like this:</p> <pre><code>&lt;a class="blah blah" id="blah blah" href="link.html"&gt;&lt;/a&gt; </code></pre> <p>How would I retrieve the value of the <code>href</code> attribute?</p>
8
2009-11-05T22:32:52Z
1,684,140
<p>If you already have the anchor, grab the <code>href</code> attribute like this:</p> <pre><code>href = anchor["href"] </code></pre>
9
2009-11-05T22:36:27Z
[ "python", "beautifulsoup" ]
BeautifulSoup - extracting attribute values
1,684,120
<p>If Beautiful Soup gives me an anchor tag like this:</p> <pre><code>&lt;a class="blah blah" id="blah blah" href="link.html"&gt;&lt;/a&gt; </code></pre> <p>How would I retrieve the value of the <code>href</code> attribute?</p>
8
2009-11-05T22:32:52Z
18,810,853
<pre><code>link.get('href') </code></pre> <p>in which 'link' is the name of your 'a' tag</p>
0
2013-09-15T09:28:16Z
[ "python", "beautifulsoup" ]
Call Ruby or Python API in C# .NET
1,684,145
<p>I have a lot of APIs/Classes that I have developed in Ruby and Python that I would like to use in my .NET apps. Is it possible to instantiate a Ruby or Python Object in C# and call its methods?</p> <p>It seems that libraries like IronPython do the opposite of this. Meaning, they allow Python to utilize .NET objects...
8
2009-11-05T22:37:12Z
1,684,168
<p>I have seen ways to call into Ruby / Python from c#. But it's easier the other way around.</p>
-1
2009-11-05T22:41:06Z
[ "c#", ".net", "python", "ruby" ]
Call Ruby or Python API in C# .NET
1,684,145
<p>I have a lot of APIs/Classes that I have developed in Ruby and Python that I would like to use in my .NET apps. Is it possible to instantiate a Ruby or Python Object in C# and call its methods?</p> <p>It seems that libraries like IronPython do the opposite of this. Meaning, they allow Python to utilize .NET objects...
8
2009-11-05T22:37:12Z
1,684,213
<p>If you can wait for C# 4.0 (you can use the beta right now), it will come with the "dynamic" keyword, and you can call IronRuby or IronPython code as described <a href="http://geekswithblogs.net/michelotti/archive/2009/08/05/c-4.0-dynamic-keyword-with-ironruby.aspx" rel="nofollow">here</a>.</p>
3
2009-11-05T22:48:32Z
[ "c#", ".net", "python", "ruby" ]
Call Ruby or Python API in C# .NET
1,684,145
<p>I have a lot of APIs/Classes that I have developed in Ruby and Python that I would like to use in my .NET apps. Is it possible to instantiate a Ruby or Python Object in C# and call its methods?</p> <p>It seems that libraries like IronPython do the opposite of this. Meaning, they allow Python to utilize .NET objects...
8
2009-11-05T22:37:12Z
1,684,954
<p>This is one of the two things that the <a href="http://DLR.CodePlex.Com/">Dynamic Language Runtime</a> is supposed to do: everybody thinks that the DLR is only for language implementors to make it easier to implement dynamic languages on the CLI. But, it is also for application writers, to make it easier to host dyn...
9
2009-11-06T02:01:16Z
[ "c#", ".net", "python", "ruby" ]
Call Ruby or Python API in C# .NET
1,684,145
<p>I have a lot of APIs/Classes that I have developed in Ruby and Python that I would like to use in my .NET apps. Is it possible to instantiate a Ruby or Python Object in C# and call its methods?</p> <p>It seems that libraries like IronPython do the opposite of this. Meaning, they allow Python to utilize .NET objects...
8
2009-11-05T22:37:12Z
1,684,982
<p>Both <a href="http://www.ironruby.net/" rel="nofollow">IronRuby</a> and <a href="http://www.codeplex.com/IronPython" rel="nofollow">IronPython</a> allow you to call Ruby and Python native modules, functions and classes. Both are supported as more or less first class languages in .NET, specifically under the DLR (Dy...
1
2009-11-06T02:09:09Z
[ "c#", ".net", "python", "ruby" ]
Uploading to the cheeseshop different versions of a package for different versions of Python
1,684,173
<p>I have an open-source Python project (called GarlicSim), and I maintain 4 different versions of it for Python versions 2.4, 2.5, 2.6 and 3.1. Yes, maybe it's unusual, but I like using as much features as possible. I keep them in 4 different forks of the repository.</p> <p>Now I want to upload my project to the chee...
5
2009-11-05T22:42:00Z
1,684,399
<pre><code>python2.4 setup.py bdist_egg upload python2.5 setup.py bdist_egg upload python2.6 setup.py bdist_egg upload python3.1 setup.py bdist_egg upload </code></pre>
3
2009-11-05T23:31:30Z
[ "python", "python-3.x", "distribution", "distutils", "pypi" ]
Saving output of a for-loop to file
1,684,194
<p>I have opened a file with blast results and printed out the hits in fasta format to the screen.</p> <p>The code looks like this:</p> <pre><code>result_handle = open("/Users/jonbra/Desktop/my_blast.xml") from Bio.Blast import NCBIXML blast_records = NCBIXML.parse(result_handle) blast_record = blast_records.next() ...
3
2009-11-05T22:45:48Z
1,684,254
<p>First, create a file object:</p> <pre><code>f = open("myfile.txt", "w") # Use "a" instead of "w" to append to file </code></pre> <p>You can print to a file object:</p> <pre><code>print &gt;&gt; f, '&gt;', alignment.title print &gt;&gt; f, hsp.sbjct </code></pre> <p>Or you can write to it:</p> <pre><code>f.write...
6
2009-11-05T22:59:03Z
[ "python", "file", "loops", "save" ]
Saving output of a for-loop to file
1,684,194
<p>I have opened a file with blast results and printed out the hits in fasta format to the screen.</p> <p>The code looks like this:</p> <pre><code>result_handle = open("/Users/jonbra/Desktop/my_blast.xml") from Bio.Blast import NCBIXML blast_records = NCBIXML.parse(result_handle) blast_record = blast_records.next() ...
3
2009-11-05T22:45:48Z
1,684,262
<p>There are two general approaches. Outside of python:</p> <pre><code>python your_program.py &gt;output_file.txt </code></pre> <p>Or, inside of Python:</p> <pre><code>out = open("output_file.txt", "w") for alignment in blast_record.alignments: for hsp in alignment.hsps: print &gt;&gt;out, '&gt;', alignm...
2
2009-11-05T23:00:35Z
[ "python", "file", "loops", "save" ]
Saving output of a for-loop to file
1,684,194
<p>I have opened a file with blast results and printed out the hits in fasta format to the screen.</p> <p>The code looks like this:</p> <pre><code>result_handle = open("/Users/jonbra/Desktop/my_blast.xml") from Bio.Blast import NCBIXML blast_records = NCBIXML.parse(result_handle) blast_record = blast_records.next() ...
3
2009-11-05T22:45:48Z
1,684,294
<p>Something like this</p> <pre><code>with open("thefile.txt","w") as f for alignment in blast_record.alignments: for hsp in alignment.hsps: f.write("&gt;%s\n"%alignment.title) f.write(hsp.sbjct+"\n") </code></pre> <p>prefer not to use <code>print &gt;&gt;</code> as that won't work anymore in Python...
4
2009-11-05T23:06:42Z
[ "python", "file", "loops", "save" ]
Saving output of a for-loop to file
1,684,194
<p>I have opened a file with blast results and printed out the hits in fasta format to the screen.</p> <p>The code looks like this:</p> <pre><code>result_handle = open("/Users/jonbra/Desktop/my_blast.xml") from Bio.Blast import NCBIXML blast_records = NCBIXML.parse(result_handle) blast_record = blast_records.next() ...
3
2009-11-05T22:45:48Z
1,684,300
<p>you can use <code>with statement</code> to ensure that file will be closed</p> <pre><code>from __future__ import with_statement with open('/Users/jonbra/Desktop/my_blast.xml', 'w') as outfile: from Bio.Blast import NCBIXML blast_records = NCBIXML.parse(result_handle) blast_record = blast_records.next()...
4
2009-11-05T23:08:04Z
[ "python", "file", "loops", "save" ]
Saving output of a for-loop to file
1,684,194
<p>I have opened a file with blast results and printed out the hits in fasta format to the screen.</p> <p>The code looks like this:</p> <pre><code>result_handle = open("/Users/jonbra/Desktop/my_blast.xml") from Bio.Blast import NCBIXML blast_records = NCBIXML.parse(result_handle) blast_record = blast_records.next() ...
3
2009-11-05T22:45:48Z
21,599,700
<p>for some reason the code above posted by OP did not work for me.. I modified a bit</p> <pre><code>from Bio.Blast import NCBIXML f = open('result.txt','w') for record in NCBIXML.parse(open("file.xml")) : for alignment in record.alignments: for hsp in alignment.hsps: f.write("&gt;%s\n"%alignme...
0
2014-02-06T10:08:32Z
[ "python", "file", "loops", "save" ]
Problem with SPARQLWrapper (Python)
1,684,197
<p>I'm making a SPARQL query against the Sesame store in localhost, using <a href="http://sparql-wrapper.sourceforge.net/" rel="nofollow">SPARQLWrapper</a>:</p> <pre><code> sparql = SPARQLWrapper('http://localhost:8080/openrdf-sesame/repositories/rep/statements') sparql.setQuery(query) sparql.setReturnFormat(JSON...
1
2009-11-05T22:46:01Z
1,690,604
<p>I've solved the problem by doing the SPARQL wrapping myself...</p>
0
2009-11-06T21:32:03Z
[ "python", "rdf", "sparql" ]
Problem with SPARQLWrapper (Python)
1,684,197
<p>I'm making a SPARQL query against the Sesame store in localhost, using <a href="http://sparql-wrapper.sourceforge.net/" rel="nofollow">SPARQLWrapper</a>:</p> <pre><code> sparql = SPARQLWrapper('http://localhost:8080/openrdf-sesame/repositories/rep/statements') sparql.setQuery(query) sparql.setReturnFormat(JSON...
1
2009-11-05T22:46:01Z
1,803,287
<p>For SPARQLWrapper you don't normally have to add the <code>statements</code> bit in the URI. I.e., this should work:</p> <pre><code>sparql = SPARQLWrapper('http://localhost:8080/openrdf-sesame/repositories/rep') </code></pre> <p>And then just continue with the rest of your code.</p>
3
2009-11-26T12:01:19Z
[ "python", "rdf", "sparql" ]
Acessing other py file's class
1,684,274
<p>I have two files: a.py b.py</p> <p>How can I access my ABC123 class defined in a.py from b.py?</p>
2
2009-11-05T23:02:43Z
1,684,280
<pre><code>import a x = a.ABC123() </code></pre> <p>or</p> <pre><code>from a import ABC123 x = ABC123() </code></pre> <p>will do the job, as long as <code>a.py</code> and <code>b.py</code> are in the same directory, or if <code>a.py</code> is in a directory in <code>sys.path</code> or in a directory in your environm...
10
2009-11-05T23:03:53Z
[ "python" ]
Acessing other py file's class
1,684,274
<p>I have two files: a.py b.py</p> <p>How can I access my ABC123 class defined in a.py from b.py?</p>
2
2009-11-05T23:02:43Z
1,684,282
<p>You need to import the objects from the other file:</p> <pre><code>from a import ABC123 </code></pre> <p>For a good discussion on this topic please see <a href="http://effbot.org/zone/import-confusion.htm" rel="nofollow">Importing Python Modules</a>:</p> <blockquote> <p>The import and from-import statements a...
2
2009-11-05T23:04:03Z
[ "python" ]
BioPython: extracting sequence IDs from a Blast output file
1,684,470
<p>I have a BLAST output file in XML format. It is 22 query sequences with 50 hits reported from each sequence. And I want to extract all the 50x22 hits. This is the code I currently have, but it only extracts the 50 hits from the first query. </p> <pre><code>from Bio.Blast import NCBIXM blast_records = NCBIXML.parse(...
3
2009-11-05T23:47:19Z
1,684,853
<p>This should get all records. The novelty compared with the original is the<br></p> <pre><code>for blast_record in blast_records </code></pre> <p>which is a python idiom to iterate through items in a "list-like" object, such as the blast_records (checking the <a href="http://www.biopython.org/DIST/docs/api/Bio.Bla...
3
2009-11-06T01:33:46Z
[ "python", "xml-parsing", "biopython", "xmlblaster" ]
BioPython: extracting sequence IDs from a Blast output file
1,684,470
<p>I have a BLAST output file in XML format. It is 22 query sequences with 50 hits reported from each sequence. And I want to extract all the 50x22 hits. This is the code I currently have, but it only extracts the 50 hits from the first query. </p> <pre><code>from Bio.Blast import NCBIXM blast_records = NCBIXML.parse(...
3
2009-11-05T23:47:19Z
2,505,667
<p>I used this code for extract all the results</p> <pre><code>from Bio.Blast import NCBIXML for record in NCBIXML.parse(open("rpoD.xml")) : print "QUERY: %s" % record.query for align in record.alignments : print " MATCH: %s..." % align.title[:60] for hsp in align.hsps : print " HSP...
2
2010-03-24T06:04:16Z
[ "python", "xml-parsing", "biopython", "xmlblaster" ]
python and sll/Exchange 2007: No suitable authentication method found
1,684,534
<p>I'm trying to send emails from a python script with smtplib, and it works with no problems with smtp through Exchange 2003, but with Exchange 2007 shows:</p> <pre><code>SMTPException: No suitable authentication method found. </code></pre> <p>Python code is the same in both cases (except server and login informatio...
2
2009-11-06T00:04:21Z
1,684,901
<p><a href="http://www.exchangeinbox.com/article.aspx?i=93" rel="nofollow">This article</a> describes how to configure Exchange 2007 for plain text auth.</p>
1
2009-11-06T01:49:31Z
[ "python", "ssl", "exchange-server-2007", "smtplib" ]
python and sll/Exchange 2007: No suitable authentication method found
1,684,534
<p>I'm trying to send emails from a python script with smtplib, and it works with no problems with smtp through Exchange 2003, but with Exchange 2007 shows:</p> <pre><code>SMTPException: No suitable authentication method found. </code></pre> <p>Python code is the same in both cases (except server and login informatio...
2
2009-11-06T00:04:21Z
23,688,528
<p>You might need to switch to STARTTLS authentication. Here's an example that helped me.</p> <p><a href="http://www.mkyong.com/python/how-do-send-email-in-python-via-smtplib/" rel="nofollow">How To Send Email In Python Via SMTPLIB</a></p>
2
2014-05-15T21:01:01Z
[ "python", "ssl", "exchange-server-2007", "smtplib" ]
How to set attributes using property decorators?
1,684,828
<p>This code returns an error: AttributeError: can't set attribute This is really a pity because I would like to use properties instead of calling the methods. Does anyone know why this simple example is not working?</p> <pre><code>#!/usr/bin/python2.6 class Bar( object ): """ ... """ @property ...
31
2009-11-06T01:27:33Z
1,684,851
<p>Is this what you want?</p> <pre><code>class C(object): def __init__(self): self._x = None @property def x(self): """I'm the 'x' property.""" return self._x @x.setter def x(self, value): self._x = value </code></pre> <p>Taken from <a href="http://docs.python.org...
71
2009-11-06T01:33:43Z
[ "python" ]
Debugging the reading of output of a Windows console app using Python
1,684,995
<p>This question is very similar to <a href="http://stackoverflow.com/questions/1124884/interact-with-a-windows-console-application-via-python">this one</a>. I want to read output from a console app of mine. The app does not terminate, nor does it take input from stdin.</p> <p>When I modify rix0rrr's solution to execu...
0
2009-11-06T02:13:26Z
1,685,792
<p>The very first thing I would check is the buffering in app.exe. If "Starting the server.\n" is being buffered and doesn't make it to the pipe, there is nothing you can do on the reader's side.</p> <p>So, try adding <code>fflush(stdout)</code> after <code>printf("Starting the server.\n")</code>.</p>
1
2009-11-06T06:26:21Z
[ "python", "windows", "process", "popen" ]
Python Tkinter Prompt
1,685,020
<p>I am trying to prompt the user to enter a string of text. Is there available with python tkinter a Javascript like prompt?</p>
2
2009-11-06T02:21:25Z
1,685,033
<p>One of those situations where I find it after the question has been posted and since I had trouble finding the answer I will keep the question up.</p> <p>You can use a <a href="http://www.pythonware.com/library/tkinter/introduction/x1164-data-entry.htm" rel="nofollow">tkSimpleDialog</a>.</p>
1
2009-11-06T02:25:21Z
[ "python", "tkinter" ]
Python Tkinter Prompt
1,685,020
<p>I am trying to prompt the user to enter a string of text. Is there available with python tkinter a Javascript like prompt?</p>
2
2009-11-06T02:21:25Z
1,685,050
<p>Yes, use <a href="http://effbot.org/tkinterbook/tkinter-entry-dialogs.htm" rel="nofollow">tkSimpleDialog.askstring</a>. Unfortunately this isn't in the main Python docs, so it's a bit hard to find.</p>
6
2009-11-06T02:30:05Z
[ "python", "tkinter" ]
Python Tkinter Prompt
1,685,020
<p>I am trying to prompt the user to enter a string of text. Is there available with python tkinter a Javascript like prompt?</p>
2
2009-11-06T02:21:25Z
11,496,956
<p>I think this is what you might want</p> <p>for python 2.7:</p> <pre><code>from Tkinter import * root = Tk() E = Entry(root) E.pack() root.mainloop() </code></pre> <p>for python 3:</p> <pre><code>from tkinter import * root = Tk() e = Entry(root) e.pack() root.mainloop() </code></pre>
-3
2012-07-16T00:52:28Z
[ "python", "tkinter" ]
Python Tkinter Prompt
1,685,020
<p>I am trying to prompt the user to enter a string of text. Is there available with python tkinter a Javascript like prompt?</p>
2
2009-11-06T02:21:25Z
31,500,579
<p>try this:</p> <pre><code>import tkinter x = tkinter.tkSimpleDialog.askstring </code></pre>
0
2015-07-19T11:14:51Z
[ "python", "tkinter" ]
Color Themes For Eclipse Python Development
1,685,079
<p>I am looking for Eclipse themes that are similar to the following and support Python/xhtml/css/js by default.</p> <p><img src="http://i.stack.imgur.com/JIAC1.png" alt="http://i.stack.imgur.com/JIAC1.png"></p>
8
2009-11-06T02:40:47Z
1,685,526
<p><a href="http://pydev.blogspot.com/2009/07/creating-dark-theme-and-exporting-and.html">Here</a>'s a dark theme and instructions on making it. <a href="http://wiki.creativecommons.org/Rewrite%5FMetadata%5FValidator/SoC%5F2008/PyDev%5Fintegration%5Fwith%5Fthe%5FDarklooks%5Ftheme">And another.</a></p> <p>There was som...
5
2009-11-06T05:07:17Z
[ "python", "eclipse", "themes" ]
Color Themes For Eclipse Python Development
1,685,079
<p>I am looking for Eclipse themes that are similar to the following and support Python/xhtml/css/js by default.</p> <p><img src="http://i.stack.imgur.com/JIAC1.png" alt="http://i.stack.imgur.com/JIAC1.png"></p>
8
2009-11-06T02:40:47Z
3,299,297
<p><a href="http://www.aptana.com/products/studio3" rel="nofollow">Aptana Studio</a> is built on Eclipse and includes themes. With PyDev it seems pretty good for Python development, although it is web-focused.</p>
1
2010-07-21T12:42:31Z
[ "python", "eclipse", "themes" ]
Color Themes For Eclipse Python Development
1,685,079
<p>I am looking for Eclipse themes that are similar to the following and support Python/xhtml/css/js by default.</p> <p><img src="http://i.stack.imgur.com/JIAC1.png" alt="http://i.stack.imgur.com/JIAC1.png"></p>
8
2009-11-06T02:40:47Z
7,836,970
<p>There is a whole website dedicated to color schemes in Eclipse <a href="http://www.eclipsecolorthemes.org/" rel="nofollow">http://www.eclipsecolorthemes.org/</a></p> <p>The color schemes on this site can be imported as an EPF preference file directly or alternatively via the Eclipse Color Theme Plugin found here: <...
3
2011-10-20T13:51:44Z
[ "python", "eclipse", "themes" ]
Python specify popen working directory via argument
1,685,157
<p>Is there a way to specify the running directory of command in python's <code>subprocess.Popen()</code> ?</p> <p>For example:</p> <pre><code>Popen('c:\mytool\tool.exe',workingdir='d:\test\local') </code></pre> <p>My python script is located in <code>C:\programs\python</code></p> <p>Is is possible to run <code>C:\...
86
2009-11-06T03:06:21Z
1,685,166
<p><code>subprocess.Popen</code> <a href="http://docs.python.org/library/subprocess.html#using-the-subprocess-module">takes a <code>cwd</code> argument</a> to set the Current Working Directory; you'll also want to escape your backslashes (<code>'d:\\test\\local'</code>), or use <code>r'd:\test\local'</code> so that the...
120
2009-11-06T03:10:03Z
[ "python", "subprocess", "popen" ]
accurately measure time python function takes
1,685,221
<p>I need to measure the time certain parts of my program take (not for debugging but as a feature in the output). Accuracy is important because the total time will be a fraction of a second.</p> <p>I was going to use the <a href="http://docs.python.org/library/time.html">time module</a> when I came across <a href="ht...
37
2009-11-06T03:25:04Z
1,685,245
<p>The timeit module looks like it's designed for doing performance testing of algorithms, rather than as simple monitoring of an application. Your best option is probably to use the time module, call <code>time.time()</code> at the beginning and end of the segment you're interested in, and subtract the two numbers. ...
8
2009-11-06T03:31:59Z
[ "python", "time", "profiling", "timeit" ]
accurately measure time python function takes
1,685,221
<p>I need to measure the time certain parts of my program take (not for debugging but as a feature in the output). Accuracy is important because the total time will be a fraction of a second.</p> <p>I was going to use the <a href="http://docs.python.org/library/time.html">time module</a> when I came across <a href="ht...
37
2009-11-06T03:25:04Z
1,685,263
<p>According to the Python <a href="http://docs.python.org/library/timeit.html" rel="nofollow">documentation</a> it has to do with the accuracy of the time function in different operating systems:</p> <blockquote> <p>The default timer function is platform dependent. On Windows, time.clock() has microsecond granu...
23
2009-11-06T03:36:26Z
[ "python", "time", "profiling", "timeit" ]
accurately measure time python function takes
1,685,221
<p>I need to measure the time certain parts of my program take (not for debugging but as a feature in the output). Accuracy is important because the total time will be a fraction of a second.</p> <p>I was going to use the <a href="http://docs.python.org/library/time.html">time module</a> when I came across <a href="ht...
37
2009-11-06T03:25:04Z
1,685,267
<p>The documentation also mentions that time.clock() and time.time() have different resolution depending on platform. On Unix, time.clock() measures CPU time as opposed to wall clock time.</p> <p>timeit also disables garbage collection when running the tests, which is probably not what you want for production code.</...
2
2009-11-06T03:37:25Z
[ "python", "time", "profiling", "timeit" ]
accurately measure time python function takes
1,685,221
<p>I need to measure the time certain parts of my program take (not for debugging but as a feature in the output). Accuracy is important because the total time will be a fraction of a second.</p> <p>I was going to use the <a href="http://docs.python.org/library/time.html">time module</a> when I came across <a href="ht...
37
2009-11-06T03:25:04Z
1,685,304
<p>Have you reviewed the functionality provided profile or cProfile?</p> <p><a href="http://docs.python.org/library/profile.html" rel="nofollow">http://docs.python.org/library/profile.html</a></p> <p>This provides much more detailed information than just printing the time before and after a function call. Maybe wort...
4
2009-11-06T03:50:22Z
[ "python", "time", "profiling", "timeit" ]
accurately measure time python function takes
1,685,221
<p>I need to measure the time certain parts of my program take (not for debugging but as a feature in the output). Accuracy is important because the total time will be a fraction of a second.</p> <p>I was going to use the <a href="http://docs.python.org/library/time.html">time module</a> when I came across <a href="ht...
37
2009-11-06T03:25:04Z
1,685,337
<p>You could build a timing context (see <a href="http://www.python.org/dev/peps/pep-0343/">PEP 343</a>) to measure blocks of code pretty easily.</p> <pre><code>from __future__ import with_statement import time class Timer(object): def __enter__(self): self.__start = time.time() def __exit__(self, ty...
27
2009-11-06T04:05:56Z
[ "python", "time", "profiling", "timeit" ]
accurately measure time python function takes
1,685,221
<p>I need to measure the time certain parts of my program take (not for debugging but as a feature in the output). Accuracy is important because the total time will be a fraction of a second.</p> <p>I was going to use the <a href="http://docs.python.org/library/time.html">time module</a> when I came across <a href="ht...
37
2009-11-06T03:25:04Z
14,778,306
<p>From Python 2.6 on timeit is not limited to input string anymore. Citing <a href="http://docs.python.org/2/library/timeit.html#timeit.Timer" rel="nofollow">the documentation</a>:</p> <blockquote> <p>Changed in version 2.6: The stmt and setup parameters can now also take objects that are callable without arguments...
2
2013-02-08T17:43:53Z
[ "python", "time", "profiling", "timeit" ]