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
What's wrong with my Python SOAPpy webservice call?
679,302
<p>I am playing around trying to call a simple SOAP webservice using the following code in the Python interpreter:</p> <pre><code>from SOAPpy import WSDL wsdl = "http://www.webservicex.net/whois.asmx?wsdl" proxy = WSDL.Proxy(wsdl) proxy.soapproxy.config.dumpSOAPOut=1 proxy.soapproxy.config.dumpSOAPIn=1 proxy.GetWhoIS(...
1
2009-03-24T21:23:21Z
679,464
<p>Your call seems all right to me, i think this could be a soappy problem or misconfigured server (although i have not checked this thoroughly).</p> <p>This document also suggests incompatibilities between soappy and webservicex.net: <a href="http://users.jyu.fi/~mweber/teaching/ITKS545/exercises/ex5.pdf" rel="nofoll...
3
2009-03-24T22:12:05Z
[ "python", "wsdl", "soappy" ]
What's wrong with my Python SOAPpy webservice call?
679,302
<p>I am playing around trying to call a simple SOAP webservice using the following code in the Python interpreter:</p> <pre><code>from SOAPpy import WSDL wsdl = "http://www.webservicex.net/whois.asmx?wsdl" proxy = WSDL.Proxy(wsdl) proxy.soapproxy.config.dumpSOAPOut=1 proxy.soapproxy.config.dumpSOAPIn=1 proxy.GetWhoIS(...
1
2009-03-24T21:23:21Z
679,581
<p>As mentioned by @ChristopheD, SOAPpy seems to be buggy for certain configurations of WDSL.</p> <p>I tried using suds (sudo easy_install suds on Ubuntu) instead, worked first time.</p> <pre><code>from suds.client import Client client = Client('http://www.webservicex.net/whois.asmx?wsdl') client.service.run_GetWhoIS...
2
2009-03-24T22:56:40Z
[ "python", "wsdl", "soappy" ]
What's wrong with my Python SOAPpy webservice call?
679,302
<p>I am playing around trying to call a simple SOAP webservice using the following code in the Python interpreter:</p> <pre><code>from SOAPpy import WSDL wsdl = "http://www.webservicex.net/whois.asmx?wsdl" proxy = WSDL.Proxy(wsdl) proxy.soapproxy.config.dumpSOAPOut=1 proxy.soapproxy.config.dumpSOAPIn=1 proxy.GetWhoIS(...
1
2009-03-24T21:23:21Z
1,501,307
<p>For some reason the client is sending the request using an outdated form that is almost never used anymore ("SOAP Section 5 encoding"). You can tell based on this:</p> <pre><code>SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" </code></pre> <p>But based on the WSDL, the service only accepts regu...
1
2009-10-01T00:15:26Z
[ "python", "wsdl", "soappy" ]
What's wrong with my Python SOAPpy webservice call?
679,302
<p>I am playing around trying to call a simple SOAP webservice using the following code in the Python interpreter:</p> <pre><code>from SOAPpy import WSDL wsdl = "http://www.webservicex.net/whois.asmx?wsdl" proxy = WSDL.Proxy(wsdl) proxy.soapproxy.config.dumpSOAPOut=1 proxy.soapproxy.config.dumpSOAPIn=1 proxy.GetWhoIS(...
1
2009-03-24T21:23:21Z
3,979,518
<p>Please check my answer to another question <a href="http://stackoverflow.com/questions/1768185/cant-call-a-webservice-method-using-soappy/2495261#2495261">here</a>. .net requires the soap action have the name space prepended.</p>
0
2010-10-20T15:26:19Z
[ "python", "wsdl", "soappy" ]
Best way to profile/optimize a website on google's appengine
679,670
<p>I'm currently trying to optimize my website, which run on the google's appengine. It's not an easy task, because I'm not using any powerful tool.</p> <p>Does anyone have experience in optimizing python code for this purpose? Have you find a good python profiler?</p>
15
2009-03-24T23:27:38Z
680,070
<p>The python site listed 3 profilers to choose from: <a href="http://docs.python.org/library/profile.html" rel="nofollow">http://docs.python.org/library/profile.html</a></p>
1
2009-03-25T02:59:14Z
[ "python", "google-app-engine" ]
Best way to profile/optimize a website on google's appengine
679,670
<p>I'm currently trying to optimize my website, which run on the google's appengine. It's not an easy task, because I'm not using any powerful tool.</p> <p>Does anyone have experience in optimizing python code for this purpose? Have you find a good python profiler?</p>
15
2009-03-24T23:27:38Z
680,832
<p>I have found <a href="http://code.google.com/p/jrfonseca/wiki/Gprof2Dot" rel="nofollow">Gprof2Dot</a> extremely useful. The output of the profiling modules I've tried as pretty unintuitive to interpret.</p> <p>Gprof2Dot turns the cProfile output into a pretty looking graph, with the slowest chain(?) highlighted, an...
13
2009-03-25T09:24:50Z
[ "python", "google-app-engine" ]
Best way to profile/optimize a website on google's appengine
679,670
<p>I'm currently trying to optimize my website, which run on the google's appengine. It's not an easy task, because I'm not using any powerful tool.</p> <p>Does anyone have experience in optimizing python code for this purpose? Have you find a good python profiler?</p>
15
2009-03-24T23:27:38Z
1,079,870
<p>In case anyone is coming here late, check out <a href="http://firepython.binaryage.com/" rel="nofollow">FirePython</a>, it will handle generating the dot graphs with gprof2dot serverside and you can view them in FireBug.</p>
1
2009-07-03T15:30:30Z
[ "python", "google-app-engine" ]
Best way to profile/optimize a website on google's appengine
679,670
<p>I'm currently trying to optimize my website, which run on the google's appengine. It's not an easy task, because I'm not using any powerful tool.</p> <p>Does anyone have experience in optimizing python code for this purpose? Have you find a good python profiler?</p>
15
2009-03-24T23:27:38Z
1,995,848
<p>For profiling the API calls, Guido van Rossum released a library called Appstats that will record and display a lot of good stuff about your app.</p> <p>You can get the library here: <a href="https://sites.google.com/site/appengineappstats/" rel="nofollow">https://sites.google.com/site/appengineappstats/</a></p> <...
3
2010-01-03T18:44:41Z
[ "python", "google-app-engine" ]
Best way to profile/optimize a website on google's appengine
679,670
<p>I'm currently trying to optimize my website, which run on the google's appengine. It's not an easy task, because I'm not using any powerful tool.</p> <p>Does anyone have experience in optimizing python code for this purpose? Have you find a good python profiler?</p>
15
2009-03-24T23:27:38Z
6,809,225
<p><a href="https://github.com/kamens/gae_mini_profiler">App Engine Mini Profiler</a> is a new, drop-in app engine performance tool that gives both API call perf information (via Appstats) and standard profiling data for all function calls (via cProfiler)</p> <p><a href="https://github.com/kamens/gae_mini_profiler">ht...
8
2011-07-24T19:49:08Z
[ "python", "google-app-engine" ]
min heap in python
679,731
<p>I'd like to store a set of objects in a min heap by defining a custom comparison function. I see there is a heapq module available as part of the python distribution. Is there a way to use a custom comparator with this module? If not, has someone else built a custom min heap?</p>
9
2009-03-24T23:52:58Z
679,742
<p>Yes, there is a way. Define a wrapping class that implements your custom comparator, and use a list of those instead of a list of your actual objects. That's about the best there is while still using the heapq module, since it provides no key= or cmp= arguments like the sorting functions/methods do.</p> <pre><code>...
12
2009-03-25T00:01:28Z
[ "python", "object", "heap", "min-heap" ]
min heap in python
679,731
<p>I'd like to store a set of objects in a min heap by defining a custom comparison function. I see there is a heapq module available as part of the python distribution. Is there a way to use a custom comparator with this module? If not, has someone else built a custom min heap?</p>
9
2009-03-24T23:52:58Z
679,831
<p>Two options (aside from Devin Jeanpierre's suggestion):</p> <ol> <li><p>Decorate your data before using the heap. This is the equivalent of the <code>key=</code> option to sorting. e.g. if you (for some reason) wanted to heapify a list of numbers according to their sine:</p> <pre><code>data = [ # list of numbers...
15
2009-03-25T00:49:56Z
[ "python", "object", "heap", "min-heap" ]
What are the viable database abstraction layers for Python
679,806
<p>I'm starting to get involved in an open source project <a href="http://www.gramps-project.org/wiki/index.php?title=Main%5FPage">Gramps</a> which is exploring switching their backend from BSDDB to a relational database. Either SQLite or MySQL we haven't fully decided and may even try to do both in some limited capaci...
11
2009-03-25T00:34:50Z
679,814
<p>Look very closely at SQLAlchemy.</p> <p>You can test and develop with SQLite.</p> <p>You can go into production with MySQL -- making essentially no changes to your applications.</p> <p>The DB-API, while widely adhered-to, has enough flexibility that (1) you aren't insulated from SQL variation in the underlying RD...
18
2009-03-25T00:40:50Z
[ "python", "sql", "mysql", "database", "sqlite" ]
What are the viable database abstraction layers for Python
679,806
<p>I'm starting to get involved in an open source project <a href="http://www.gramps-project.org/wiki/index.php?title=Main%5FPage">Gramps</a> which is exploring switching their backend from BSDDB to a relational database. Either SQLite or MySQL we haven't fully decided and may even try to do both in some limited capaci...
11
2009-03-25T00:34:50Z
679,819
<p>Accessing a proper database from Python is almost always done using a DB-API 2.0-compliant adapter module. While all DB-API modules have identical APIs (or very similar; not all backends support all features), if you are writing the SQL yourself, you will probably be writing SQL in a product-specific dialect, so the...
4
2009-03-25T00:43:57Z
[ "python", "sql", "mysql", "database", "sqlite" ]
What are the viable database abstraction layers for Python
679,806
<p>I'm starting to get involved in an open source project <a href="http://www.gramps-project.org/wiki/index.php?title=Main%5FPage">Gramps</a> which is exploring switching their backend from BSDDB to a relational database. Either SQLite or MySQL we haven't fully decided and may even try to do both in some limited capaci...
11
2009-03-25T00:34:50Z
679,963
<p>CouchDB is not a relational database, so it doesn't have a DB-API interface. It's a document database which means it wouldn't be as useful for Gramps because it would require some contortions to identify links between related people. On top of that it can only run in client/server mode.</p> <p>Any ORM like SQLAlc...
2
2009-03-25T02:02:43Z
[ "python", "sql", "mysql", "database", "sqlite" ]
What are the viable database abstraction layers for Python
679,806
<p>I'm starting to get involved in an open source project <a href="http://www.gramps-project.org/wiki/index.php?title=Main%5FPage">Gramps</a> which is exploring switching their backend from BSDDB to a relational database. Either SQLite or MySQL we haven't fully decided and may even try to do both in some limited capaci...
11
2009-03-25T00:34:50Z
680,135
<p>I really like <a href="https://storm.canonical.com/" rel="nofollow">Storm</a>:</p> <blockquote> <p>Storm is an object-relational mapper (ORM) for Python developed at Canonical. The project has been in development for more than a year for use in Canonical projects such as Launchpad, and has recently been...
2
2009-03-25T03:33:36Z
[ "python", "sql", "mysql", "database", "sqlite" ]
What are the viable database abstraction layers for Python
679,806
<p>I'm starting to get involved in an open source project <a href="http://www.gramps-project.org/wiki/index.php?title=Main%5FPage">Gramps</a> which is exploring switching their backend from BSDDB to a relational database. Either SQLite or MySQL we haven't fully decided and may even try to do both in some limited capaci...
11
2009-03-25T00:34:50Z
680,845
<p>If your project will ever have any real complexity, stay away from ORMs.</p> <p><a href="http://blogs.tedneward.com/2006/06/26/The+Vietnam+Of+Computer+Science.aspx" rel="nofollow">http://blogs.tedneward.com/2006/06/26/The+Vietnam+Of+Computer+Science.aspx</a></p>
0
2009-03-25T09:28:29Z
[ "python", "sql", "mysql", "database", "sqlite" ]
What are the viable database abstraction layers for Python
679,806
<p>I'm starting to get involved in an open source project <a href="http://www.gramps-project.org/wiki/index.php?title=Main%5FPage">Gramps</a> which is exploring switching their backend from BSDDB to a relational database. Either SQLite or MySQL we haven't fully decided and may even try to do both in some limited capaci...
11
2009-03-25T00:34:50Z
689,202
<p>When I started converting a legacy app to use an ORM I looked into SQLObject and SQLAlchemy. At first I went with SQLObject because it looked familiar (past Django experience) and SQLAlchemy seemed complicated. After about 2 hours I started to hit walls with SQLObject. I then looked at SQLAlchemy again and was insta...
0
2009-03-27T10:19:44Z
[ "python", "sql", "mysql", "database", "sqlite" ]
What are the viable database abstraction layers for Python
679,806
<p>I'm starting to get involved in an open source project <a href="http://www.gramps-project.org/wiki/index.php?title=Main%5FPage">Gramps</a> which is exploring switching their backend from BSDDB to a relational database. Either SQLite or MySQL we haven't fully decided and may even try to do both in some limited capaci...
11
2009-03-25T00:34:50Z
7,248,704
<p>I think that CouchDB would be best choice for such project as Gramps.</p> <p>Useful CouchDB features for Gramps:</p> <ul> <li><p>No schema, no migrations.</p></li> <li><p>Support for storing files directly to database, for example family photos, etc.: <a href="http://guide.couchdb.org/draft/api.html#attachments" r...
0
2011-08-30T19:29:10Z
[ "python", "sql", "mysql", "database", "sqlite" ]
What are the viable database abstraction layers for Python
679,806
<p>I'm starting to get involved in an open source project <a href="http://www.gramps-project.org/wiki/index.php?title=Main%5FPage">Gramps</a> which is exploring switching their backend from BSDDB to a relational database. Either SQLite or MySQL we haven't fully decided and may even try to do both in some limited capaci...
11
2009-03-25T00:34:50Z
16,901,868
<p>web2py has a database abstraction layer that can be used in a standalone manner. We switched between sqlite3, Microsoft SQL Server, Oracle and MySQL with zero code changes. Impressed.</p>
0
2013-06-03T16:54:42Z
[ "python", "sql", "mysql", "database", "sqlite" ]
Problem with python curl while submitting file
679,966
<pre><code>#!/usr/bin/python import pycurl import re import StringIO #CONSTANTS URL = "http://www.imagehost.org" FILE = "/datos/poop1.jpg" POST_DATA = [("a", "upload"), ("file[]", (pycurl.FORM_FILE, FILE))] buffer = StringIO.StringIO() c = pycurl.Curl() c.setopt( c.URL, URL ) c.setopt( c.POST, 1 ) c.setopt( c.PO...
2
2009-03-25T02:03:46Z
680,307
<p>I believe the argument for <code>POSTFIELDS</code> needs to be a simple URL encoded string, for example:</p> <pre><code>POST_DATA = 'a=foo&amp;b=bar' </code></pre> <p>Next, I'm not sure about your FILE stuff. Check out <a href="http://curl.haxx.se/mail/curlpython-2007-03/0003.html" rel="nofollow">this mail messag...
1
2009-03-25T05:17:28Z
[ "python", "upload", "curl" ]
Problem with python curl while submitting file
679,966
<pre><code>#!/usr/bin/python import pycurl import re import StringIO #CONSTANTS URL = "http://www.imagehost.org" FILE = "/datos/poop1.jpg" POST_DATA = [("a", "upload"), ("file[]", (pycurl.FORM_FILE, FILE))] buffer = StringIO.StringIO() c = pycurl.Curl() c.setopt( c.URL, URL ) c.setopt( c.POST, 1 ) c.setopt( c.PO...
2
2009-03-25T02:03:46Z
4,943,261
<p>The pycurl documentation is not so clear on this, but the HTTPPOST option can take a list of tuples, each exactly two elements long. Each tuple's first argument is the form field name, the second is the value.</p> <p>However, the value may be a tuple as well. This tuple must contains pairs of data relating to that ...
6
2011-02-09T09:55:40Z
[ "python", "upload", "curl" ]
Problem with python curl while submitting file
679,966
<pre><code>#!/usr/bin/python import pycurl import re import StringIO #CONSTANTS URL = "http://www.imagehost.org" FILE = "/datos/poop1.jpg" POST_DATA = [("a", "upload"), ("file[]", (pycurl.FORM_FILE, FILE))] buffer = StringIO.StringIO() c = pycurl.Curl() c.setopt( c.URL, URL ) c.setopt( c.POST, 1 ) c.setopt( c.PO...
2
2009-03-25T02:03:46Z
7,036,556
<p>Error 26 (in "pycurl.error: (26, 'failed creating formpost data')") means that the filename you specified to upload does not exist. I was running into this same error, and that was definitely the problem. See the curl source code for the location that it generates error 26.</p>
1
2011-08-12T06:50:18Z
[ "python", "upload", "curl" ]
Python: How to extract variable name of a dictionary entry?
680,032
<p>I'm wondering how I would go about finding the variable name of a dictionary element:</p> <p>For example:</p> <pre><code> &gt;&gt;&gt;dict1={} &gt;&gt;&gt;dict2={} &gt;&gt;&gt;dict1['0001']='0002' &gt;&gt;&gt;dict2['nth_dict_item']=dict1 &gt;&gt;&gt;print dict2 {'nth_dict_item': {'0001': '0...
2
2009-03-25T02:36:07Z
680,051
<p>A variable name is just a name--it has no real meaning as far as the program is concerned, except as a convenience to the programmer (this isn't quite true in Python, but bear with me). As far as the Python interpreter is concerned, the name <code>dict1</code> is just the programmer's way of telling Python to look a...
9
2009-03-25T02:47:39Z
[ "python", "dictionary", "variables", "lookup" ]
Python: How to extract variable name of a dictionary entry?
680,032
<p>I'm wondering how I would go about finding the variable name of a dictionary element:</p> <p>For example:</p> <pre><code> &gt;&gt;&gt;dict1={} &gt;&gt;&gt;dict2={} &gt;&gt;&gt;dict1['0001']='0002' &gt;&gt;&gt;dict2['nth_dict_item']=dict1 &gt;&gt;&gt;print dict2 {'nth_dict_item': {'0001': '0...
2
2009-03-25T02:36:07Z
680,101
<p>To add what zenazn said:</p> <blockquote> <p>But how can I turn that id back into a variable name?</p> </blockquote> <p>The short answer is that you don't want really want to. If you think you need to, there's something very wrong with the design of your program. If you told us more concretely what problem you w...
7
2009-03-25T03:11:28Z
[ "python", "dictionary", "variables", "lookup" ]
Python: How to extract variable name of a dictionary entry?
680,032
<p>I'm wondering how I would go about finding the variable name of a dictionary element:</p> <p>For example:</p> <pre><code> &gt;&gt;&gt;dict1={} &gt;&gt;&gt;dict2={} &gt;&gt;&gt;dict1['0001']='0002' &gt;&gt;&gt;dict2['nth_dict_item']=dict1 &gt;&gt;&gt;print dict2 {'nth_dict_item': {'0001': '0...
2
2009-03-25T02:36:07Z
680,205
<blockquote> <p>How can I go about making it tell me that dict2['nth_dict_item'] is or is referencing "dict1" ?</p> </blockquote> <pre><code>&gt;&gt;&gt; print dict2['nth_dict_item'] is dict1 True </code></pre>
0
2009-03-25T04:21:11Z
[ "python", "dictionary", "variables", "lookup" ]
Python: How to extract variable name of a dictionary entry?
680,032
<p>I'm wondering how I would go about finding the variable name of a dictionary element:</p> <p>For example:</p> <pre><code> &gt;&gt;&gt;dict1={} &gt;&gt;&gt;dict2={} &gt;&gt;&gt;dict1['0001']='0002' &gt;&gt;&gt;dict2['nth_dict_item']=dict1 &gt;&gt;&gt;print dict2 {'nth_dict_item': {'0001': '0...
2
2009-03-25T02:36:07Z
680,221
<p>You need to rethink your design.</p> <p>A quick hack would be to actually put the variable name in ...</p> <pre><code>dict2['item_n'] = 'dict1' </code></pre> <p>or maybe use a tuple ..</p> <pre><code>dict2['item_n'] = ('dict1', dict1) </code></pre> <p>There's a function called <code>locals()</code> which gives ...
1
2009-03-25T04:31:30Z
[ "python", "dictionary", "variables", "lookup" ]
Python: How to extract variable name of a dictionary entry?
680,032
<p>I'm wondering how I would go about finding the variable name of a dictionary element:</p> <p>For example:</p> <pre><code> &gt;&gt;&gt;dict1={} &gt;&gt;&gt;dict2={} &gt;&gt;&gt;dict1['0001']='0002' &gt;&gt;&gt;dict2['nth_dict_item']=dict1 &gt;&gt;&gt;print dict2 {'nth_dict_item': {'0001': '0...
2
2009-03-25T02:36:07Z
680,259
<p>The trivial answer: instead of</p> <pre><code>WhichDict[WhichDict.keys()[0]][2]='newcomment' </code></pre> <p>use:</p> <pre><code>WhichDict.values()[0][2]='newcomment' </code></pre> <p>But using a dictionary to represent a single movie is grossly inappropriate. Why not use a class instead?</p> <pre><code>class...
4
2009-03-25T04:49:49Z
[ "python", "dictionary", "variables", "lookup" ]
Python: How to extract variable name of a dictionary entry?
680,032
<p>I'm wondering how I would go about finding the variable name of a dictionary element:</p> <p>For example:</p> <pre><code> &gt;&gt;&gt;dict1={} &gt;&gt;&gt;dict2={} &gt;&gt;&gt;dict1['0001']='0002' &gt;&gt;&gt;dict2['nth_dict_item']=dict1 &gt;&gt;&gt;print dict2 {'nth_dict_item': {'0001': '0...
2
2009-03-25T02:36:07Z
680,270
<p>Right now, for each movie, you're doing:</p> <pre><code>dict_n = {} dict_n["000n"] = [movie_duration,movie_type,comments] </code></pre> <p>with only one entry per dict. Then you're storing multiple movie dicts in a central one:</p> <pre><code>dict_database = {} dict_database["0001"] = dict_1 dict_database["0002"...
1
2009-03-25T04:56:36Z
[ "python", "dictionary", "variables", "lookup" ]
Python: How to extract variable name of a dictionary entry?
680,032
<p>I'm wondering how I would go about finding the variable name of a dictionary element:</p> <p>For example:</p> <pre><code> &gt;&gt;&gt;dict1={} &gt;&gt;&gt;dict2={} &gt;&gt;&gt;dict1['0001']='0002' &gt;&gt;&gt;dict2['nth_dict_item']=dict1 &gt;&gt;&gt;print dict2 {'nth_dict_item': {'0001': '0...
2
2009-03-25T02:36:07Z
681,124
<p>Use <a href="http://guppy-pe.sourceforge.net/" rel="nofollow">Guppy</a>.</p> <pre><code>from guppy import hpy h=hpy() h.iso(dict2['nth_dict_item']).sp 0: h.Root.i0_modules['__main__'].__dict__['dict1'] </code></pre>
0
2009-03-25T11:12:35Z
[ "python", "dictionary", "variables", "lookup" ]
How do I tell which Python interpreter I'm using?
680,207
<p>I am using Python 2.5.2. How can I tell whether it is <code>CPython</code> or <code>IronPython</code> or <code>Jython</code>?</p> <p>Another question: how can I <strong>use a DLL</strong> developed in VB.NET in my project?</p>
1
2009-03-25T04:23:52Z
680,222
<p>If you downloaded it as the default thing from python.org, it's CPython. That's the “normal” version of Python, the one you get when you use the command “python”, and the one you'll have unless you specifically went looking for the projects targeting Java/CIL.</p> <p>And it's CPython because neither of the ...
5
2009-03-25T04:31:54Z
[ "python" ]
How do I tell which Python interpreter I'm using?
680,207
<p>I am using Python 2.5.2. How can I tell whether it is <code>CPython</code> or <code>IronPython</code> or <code>Jython</code>?</p> <p>Another question: how can I <strong>use a DLL</strong> developed in VB.NET in my project?</p>
1
2009-03-25T04:23:52Z
680,226
<pre><code>import sys print sys.version </code></pre>
0
2009-03-25T04:33:09Z
[ "python" ]
How do I tell which Python interpreter I'm using?
680,207
<p>I am using Python 2.5.2. How can I tell whether it is <code>CPython</code> or <code>IronPython</code> or <code>Jython</code>?</p> <p>Another question: how can I <strong>use a DLL</strong> developed in VB.NET in my project?</p>
1
2009-03-25T04:23:52Z
680,227
<p>If you are typing "python" to launch it, it is probably CPython. IronPython's executable name is "ipy".</p>
3
2009-03-25T04:34:18Z
[ "python" ]
How do I tell which Python interpreter I'm using?
680,207
<p>I am using Python 2.5.2. How can I tell whether it is <code>CPython</code> or <code>IronPython</code> or <code>Jython</code>?</p> <p>Another question: how can I <strong>use a DLL</strong> developed in VB.NET in my project?</p>
1
2009-03-25T04:23:52Z
680,233
<p>Well since the first part of your question has been answered, I'll tackle the second part. .NET dll's can be accessed from python in various ways. If you are using ironpython it makes this especially easy, since all .NET languages can interact with eachother fairly seamlessly. In this case you would access your dll ...
1
2009-03-25T04:37:13Z
[ "python" ]
Using MultipartPostHandler to POST form-data with Python
680,305
<p>Problem: When POSTing data with Python's urllib2, all data is URL encoded and sent as Content-Type: application/x-www-form-urlencoded. When uploading files, the Content-Type should instead be set to multipart/form-data and the contents be MIME encoded. A discussion of this problem is here: <a href="http://code.acti...
44
2009-03-25T05:14:37Z
681,182
<p>Found this recipe to post multipart using <code>httplib</code> directly (no external libraries involved)</p> <pre><code>import httplib import mimetypes def post_multipart(host, selector, fields, files): content_type, body = encode_multipart_formdata(fields, files) h = httplib.HTTP(host) h.putrequest('P...
29
2009-03-25T11:29:54Z
[ "python", "file", "upload", "urllib2", "multipartform-data" ]
Using MultipartPostHandler to POST form-data with Python
680,305
<p>Problem: When POSTing data with Python's urllib2, all data is URL encoded and sent as Content-Type: application/x-www-form-urlencoded. When uploading files, the Content-Type should instead be set to multipart/form-data and the contents be MIME encoded. A discussion of this problem is here: <a href="http://code.acti...
44
2009-03-25T05:14:37Z
688,193
<p>It seems that the easiest and most compatible way to get around this problem is to use the 'poster' module.</p> <pre><code># test_client.py from poster.encode import multipart_encode from poster.streaminghttp import register_openers import urllib2 # Register the streaming http handlers with urllib2 register_opener...
55
2009-03-27T01:31:25Z
[ "python", "file", "upload", "urllib2", "multipartform-data" ]
Using MultipartPostHandler to POST form-data with Python
680,305
<p>Problem: When POSTing data with Python's urllib2, all data is URL encoded and sent as Content-Type: application/x-www-form-urlencoded. When uploading files, the Content-Type should instead be set to multipart/form-data and the contents be MIME encoded. A discussion of this problem is here: <a href="http://code.acti...
44
2009-03-25T05:14:37Z
18,120,930
<p>Just use <a href="http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file" rel="nofollow"><strong>python-requests</strong></a>, it will set proper headers and do upload for you:</p> <pre><code>import requests files = {"form_input_field_name": open("filename", "rb")} requests.post("...
24
2013-08-08T08:04:24Z
[ "python", "file", "upload", "urllib2", "multipartform-data" ]
Using MultipartPostHandler to POST form-data with Python
680,305
<p>Problem: When POSTing data with Python's urllib2, all data is URL encoded and sent as Content-Type: application/x-www-form-urlencoded. When uploading files, the Content-Type should instead be set to multipart/form-data and the contents be MIME encoded. A discussion of this problem is here: <a href="http://code.acti...
44
2009-03-25T05:14:37Z
26,028,984
<p>I what a coincide, 2 years, 6 months ago I create the project </p> <p><a href="https://pypi.python.org/pypi/MultipartPostHandler2" rel="nofollow">https://pypi.python.org/pypi/MultipartPostHandler2</a> , that fix MultipartPostHandler for utf-8 systems. I also have done some minor improvements , you are welcome to te...
0
2014-09-25T01:18:06Z
[ "python", "file", "upload", "urllib2", "multipartform-data" ]
Using MultipartPostHandler to POST form-data with Python
680,305
<p>Problem: When POSTing data with Python's urllib2, all data is URL encoded and sent as Content-Type: application/x-www-form-urlencoded. When uploading files, the Content-Type should instead be set to multipart/form-data and the contents be MIME encoded. A discussion of this problem is here: <a href="http://code.acti...
44
2009-03-25T05:14:37Z
29,332,627
<p>I ran into the same problem and I needed to do a multipart form post without using external libraries. I wrote a whole <a href="http://blog.thesparktree.com/post/114053773684/the-unfortunately-long-story-dealing-with" rel="nofollow">blogpost about the issues I ran into</a>.</p> <p>I ended up using a modified versio...
0
2015-03-29T17:49:20Z
[ "python", "file", "upload", "urllib2", "multipartform-data" ]
Python 2.5.2 continued
680,336
<p>This is a continuation of my question Python2.5.2 The code i developed is working fine with clr.Addreference(). Now thee problem is I have to load ny script which uses dll developed in .NET to another application.They had used QT for its implementation.There is a Script console in that application.When ii entered 'i...
0
2009-03-25T05:34:45Z
680,367
<p>You won't be able to run your script in that application. The script console in that QT application doubtlessly uses plain ol' CPython instead of IronPython. There's no real good way to change that without significant surgery to the application that's hosting the python console.</p>
3
2009-03-25T05:50:48Z
[ "python", "ironpython" ]
python create slice object from string
680,826
<p>I'd like to create a slice object from a string; right now the only way seems through a cumbersome hacky eval statement</p> <pre><code>class getslice: def __getitem__(self, idx): return idx[0] eval("getslice()[%s, 1]" %(":-1")) </code></pre> <p>thanks in advance.</p> <p><strong>Edit</strong>: Sorry if the ori...
5
2009-03-25T09:23:52Z
680,843
<p>use operator module:</p> <p>in Python 2.5 or earlier: <a href="http://docs.python.org/library/operator.html#operator.getslice" rel="nofollow"><code>operator.getslice(obj,start,end)</code></a></p> <p>in Python 2.6 or later: <a href="http://docs.python.org/library/operator.html#operator.getitem" rel="nofollow"><cod...
2
2009-03-25T09:27:51Z
[ "python", "indexing", "slice" ]
python create slice object from string
680,826
<p>I'd like to create a slice object from a string; right now the only way seems through a cumbersome hacky eval statement</p> <pre><code>class getslice: def __getitem__(self, idx): return idx[0] eval("getslice()[%s, 1]" %(":-1")) </code></pre> <p>thanks in advance.</p> <p><strong>Edit</strong>: Sorry if the ori...
5
2009-03-25T09:23:52Z
680,889
<p>If you want a slice object, why don't you just instantiate one?</p> <pre><code>s = slice(start, stop, step) </code></pre> <p>What are you meaning by "creating it from a string"?</p>
4
2009-03-25T09:46:12Z
[ "python", "indexing", "slice" ]
python create slice object from string
680,826
<p>I'd like to create a slice object from a string; right now the only way seems through a cumbersome hacky eval statement</p> <pre><code>class getslice: def __getitem__(self, idx): return idx[0] eval("getslice()[%s, 1]" %(":-1")) </code></pre> <p>thanks in advance.</p> <p><strong>Edit</strong>: Sorry if the ori...
5
2009-03-25T09:23:52Z
681,895
<p>A slice object is usually created using subscript notation, this notation uses slice() internally, as stated on the <a href="http://docs.python.org/library/functions.html#slice" rel="nofollow">slice() documentation</a>. What you want to do is:</p> <pre><code>your_string[start:end] </code></pre> <p>From <a href="ht...
0
2009-03-25T14:42:28Z
[ "python", "indexing", "slice" ]
python create slice object from string
680,826
<p>I'd like to create a slice object from a string; right now the only way seems through a cumbersome hacky eval statement</p> <pre><code>class getslice: def __getitem__(self, idx): return idx[0] eval("getslice()[%s, 1]" %(":-1")) </code></pre> <p>thanks in advance.</p> <p><strong>Edit</strong>: Sorry if the ori...
5
2009-03-25T09:23:52Z
681,949
<pre><code>slice(*[{True: lambda n: None, False: int}[x == ''](x) for x in (mystring.split(':') + ['', '', ''])[:3]]) </code></pre>
3
2009-03-25T14:51:40Z
[ "python", "indexing", "slice" ]
python create slice object from string
680,826
<p>I'd like to create a slice object from a string; right now the only way seems through a cumbersome hacky eval statement</p> <pre><code>class getslice: def __getitem__(self, idx): return idx[0] eval("getslice()[%s, 1]" %(":-1")) </code></pre> <p>thanks in advance.</p> <p><strong>Edit</strong>: Sorry if the ori...
5
2009-03-25T09:23:52Z
23,895,339
<p>I end up here because I wanted my script to accept a python-like splice argument and render it into a list of integers, I did it with a function that seems like it answers the OP's question:</p> <pre><code># create a slice object from a string def get_slice_obj(slicearg): slice_ints = tuple([ int(n) for n in sl...
1
2014-05-27T17:18:06Z
[ "python", "indexing", "slice" ]
Python dynamic function names
680,941
<p>I'm looking for a better way to call functions based on a variable in Python vs using if/else statements like below. Each status code has a corresponding function</p> <pre><code>if status == 'CONNECT': return connect(*args, **kwargs) elif status == 'RAWFEED': return rawfeed(*args, **kwargs) elif status == '...
9
2009-03-25T10:04:26Z
680,954
<p>you might find <a href="http://docs.python.org/library/functions.html?highlight=getattr#getattr"><code>getattr</code></a> useful, I guess</p> <pre><code>import module getattr(module, status.lower())(*args, **kwargs) </code></pre>
35
2009-03-25T10:08:32Z
[ "python", "factory" ]
Python dynamic function names
680,941
<p>I'm looking for a better way to call functions based on a variable in Python vs using if/else statements like below. Each status code has a corresponding function</p> <pre><code>if status == 'CONNECT': return connect(*args, **kwargs) elif status == 'RAWFEED': return rawfeed(*args, **kwargs) elif status == '...
9
2009-03-25T10:04:26Z
680,958
<p>assuming that these functions belong to some module:</p> <pre><code>import module return getattr(module, status.lower()).__call__(*args, **kwargs) </code></pre>
15
2009-03-25T10:10:11Z
[ "python", "factory" ]
Python dynamic function names
680,941
<p>I'm looking for a better way to call functions based on a variable in Python vs using if/else statements like below. Each status code has a corresponding function</p> <pre><code>if status == 'CONNECT': return connect(*args, **kwargs) elif status == 'RAWFEED': return rawfeed(*args, **kwargs) elif status == '...
9
2009-03-25T10:04:26Z
680,967
<p>The canonical way to do this is to use a dictionary to emulate <code>switch</code> or <code>if/elif</code>. You will find several questions to similar problems here on SO.</p> <p>Put your functions into a dictionary with your status codes as keys:</p> <pre><code>funcs = { 'CONNECT': connect, 'RAWFEED': raw...
15
2009-03-25T10:13:15Z
[ "python", "factory" ]
Python dynamic function names
680,941
<p>I'm looking for a better way to call functions based on a variable in Python vs using if/else statements like below. Each status code has a corresponding function</p> <pre><code>if status == 'CONNECT': return connect(*args, **kwargs) elif status == 'RAWFEED': return rawfeed(*args, **kwargs) elif status == '...
9
2009-03-25T10:04:26Z
680,980
<p>some change from previous one:</p> <pre><code>funcs = { 'CONNECT': connect, 'RAWFEED': rawfeed, 'RAWCONFIG' : rawconfig, 'TESTFEED': testfeed } func = funcs.get('status') if func: func(*args, **kwargs) </code></pre>
-1
2009-03-25T10:16:46Z
[ "python", "factory" ]
Python dynamic function names
680,941
<p>I'm looking for a better way to call functions based on a variable in Python vs using if/else statements like below. Each status code has a corresponding function</p> <pre><code>if status == 'CONNECT': return connect(*args, **kwargs) elif status == 'RAWFEED': return rawfeed(*args, **kwargs) elif status == '...
9
2009-03-25T10:04:26Z
680,984
<p>it seams that you can use getattr in a slightly different (in my opinion more elegant way)</p> <pre><code>import math getattr(math, 'sin')(1) </code></pre> <p>or if function is imported like below</p> <pre><code>from math import sin </code></pre> <p>sin is now in namespace so you can call it by</p> <pre><code>v...
5
2009-03-25T10:18:46Z
[ "python", "factory" ]
Python dynamic function names
680,941
<p>I'm looking for a better way to call functions based on a variable in Python vs using if/else statements like below. Each status code has a corresponding function</p> <pre><code>if status == 'CONNECT': return connect(*args, **kwargs) elif status == 'RAWFEED': return rawfeed(*args, **kwargs) elif status == '...
9
2009-03-25T10:04:26Z
680,986
<p>Look at this: <a href="http://diveintopython.net/power_of_introspection/getattr.html#d0e9362" rel="nofollow">getattra as a function dispatcher</a></p>
3
2009-03-25T10:19:41Z
[ "python", "factory" ]
Python dynamic function names
680,941
<p>I'm looking for a better way to call functions based on a variable in Python vs using if/else statements like below. Each status code has a corresponding function</p> <pre><code>if status == 'CONNECT': return connect(*args, **kwargs) elif status == 'RAWFEED': return rawfeed(*args, **kwargs) elif status == '...
9
2009-03-25T10:04:26Z
681,007
<p>I encountered the same problem previously. Have a look at this question, I think its what you are looking for.</p> <p><a href="http://stackoverflow.com/questions/277965/dictionary-or-if-statements-jython">Dictionary or If Statements</a></p> <p>Hope this is helpful</p> <p>Eef</p>
1
2009-03-25T10:27:10Z
[ "python", "factory" ]
Python dynamic function names
680,941
<p>I'm looking for a better way to call functions based on a variable in Python vs using if/else statements like below. Each status code has a corresponding function</p> <pre><code>if status == 'CONNECT': return connect(*args, **kwargs) elif status == 'RAWFEED': return rawfeed(*args, **kwargs) elif status == '...
9
2009-03-25T10:04:26Z
681,028
<p>Some improvement to SilentGhost's answer:</p> <pre><code>globals()[status.lower()](*args, **kwargs) </code></pre> <p>if you want to call the function defined in the current module.</p> <p>Though it looks ugly. I'd use the solution with dictionary.</p>
4
2009-03-25T10:33:39Z
[ "python", "factory" ]
Whats the difference between list[-1:][0] and list[len(list)-1]?
681,123
<p>Lest say you want the last element of a python list: what is the difference between</p> <pre><code>myList[-1:][0] </code></pre> <p>and</p> <pre><code>myList[len(myList)-1] </code></pre> <p>I thought there was no difference but then I tried this </p> <pre><code>&gt;&gt;&gt; list = [0] &gt;&gt;&gt; list[-1:][0] 0...
7
2009-03-25T11:11:46Z
681,135
<p>if you use slicing [-1:], the returned list is a shallow-copy, not reference. so [-1:][0] modifies the new list. [len(list)-1] is reference to last object.</p>
14
2009-03-25T11:15:40Z
[ "python", "list", "slice" ]
Whats the difference between list[-1:][0] and list[len(list)-1]?
681,123
<p>Lest say you want the last element of a python list: what is the difference between</p> <pre><code>myList[-1:][0] </code></pre> <p>and</p> <pre><code>myList[len(myList)-1] </code></pre> <p>I thought there was no difference but then I tried this </p> <pre><code>&gt;&gt;&gt; list = [0] &gt;&gt;&gt; list[-1:][0] 0...
7
2009-03-25T11:11:46Z
681,138
<p><code>list[-1:]</code> creates a new list. To get the same behaviour as <code>list[len(list)-1]</code> it would have to return a view of some kind of <code>list</code>, but as I said, it creates a new temporary list. You then proceed to edit the temporary list.</p> <p>Anyway, you know you can use <code>list[-1]</co...
9
2009-03-25T11:17:16Z
[ "python", "list", "slice" ]
Whats the difference between list[-1:][0] and list[len(list)-1]?
681,123
<p>Lest say you want the last element of a python list: what is the difference between</p> <pre><code>myList[-1:][0] </code></pre> <p>and</p> <pre><code>myList[len(myList)-1] </code></pre> <p>I thought there was no difference but then I tried this </p> <pre><code>&gt;&gt;&gt; list = [0] &gt;&gt;&gt; list[-1:][0] 0...
7
2009-03-25T11:11:46Z
681,196
<p>Slicing creates copy (shallow copy). It's often used as an shallow copy idiom.</p> <p>i.e.</p> <pre><code>list2 = list1[:] </code></pre> <p>is equivalent to</p> <pre><code>import copy list2 = copy.copy(list1) </code></pre>
3
2009-03-25T11:34:54Z
[ "python", "list", "slice" ]
Game map from Code
681,310
<p>It's a long one so you might want to get that cup of tea/coffee you've been holding off on ;)</p> <p>I run a game called World of Arl, it's a turn based strategy game akin to Risk or Diplomacy. Each player has a set of cities, armies and whatnot. The question revolves around the display of these things. Currently t...
2
2009-03-25T12:16:19Z
681,340
<p>I'd store a game map in code as a <a href="http://en.wikipedia.org/wiki/Graph%5F%28mathematics%29" rel="nofollow">graph</a>. </p> <p>Each node would represent a country/city and each edge would represent adjacency. Once you have a map like that, I'm sure you can find many resources on AI (pathfinding, strategy, e...
5
2009-03-25T12:24:27Z
[ "python" ]
Game map from Code
681,310
<p>It's a long one so you might want to get that cup of tea/coffee you've been holding off on ;)</p> <p>I run a game called World of Arl, it's a turn based strategy game akin to Risk or Diplomacy. Each player has a set of cities, armies and whatnot. The question revolves around the display of these things. Currently t...
2
2009-03-25T12:16:19Z
681,386
<p>IMO, the map should be rendered in the first place instead of being a bitmap. What you should be doing is to have separate objects each knowing its dimensions clearly such as a generic Area class and classes like City, Town etc derived from this class. Your objects should have all the information about their locatio...
1
2009-03-25T12:36:36Z
[ "python" ]
Game map from Code
681,310
<p>It's a long one so you might want to get that cup of tea/coffee you've been holding off on ;)</p> <p>I run a game called World of Arl, it's a turn based strategy game akin to Risk or Diplomacy. Each player has a set of cities, armies and whatnot. The question revolves around the display of these things. Currently t...
2
2009-03-25T12:16:19Z
681,393
<p>If you just want to do e.g. 2D hit-testing on the map, then storing it yourself is fine. There are a few possibilities for how you can store the information:</p> <ul> <li>A polygon per island</li> <li>Representing each island as union of a list rectangles (commonly used by windowing systems)</li> <li>Creating a spe...
1
2009-03-25T12:39:28Z
[ "python" ]
Game map from Code
681,310
<p>It's a long one so you might want to get that cup of tea/coffee you've been holding off on ;)</p> <p>I run a game called World of Arl, it's a turn based strategy game akin to Risk or Diplomacy. Each player has a set of cities, armies and whatnot. The question revolves around the display of these things. Currently t...
2
2009-03-25T12:16:19Z
681,401
<p>You're going to have to translate your map into an abstract representation of some kind. Either a grid (hex or square) or a graph as xynth suggests. That's the only way you're going to be able to apply things like pathfinding algorithms to it.</p>
2
2009-03-25T12:40:27Z
[ "python" ]
Game map from Code
681,310
<p>It's a long one so you might want to get that cup of tea/coffee you've been holding off on ;)</p> <p>I run a game called World of Arl, it's a turn based strategy game akin to Risk or Diplomacy. Each player has a set of cities, armies and whatnot. The question revolves around the display of these things. Currently t...
2
2009-03-25T12:16:19Z
681,447
<p>The key thing to realize here is that you don't have to use just <strong>one</strong> map. You can use two maps:</p> <ul> <li>The one you already have which is drawn on screen</li> <li>A hidden map which isn't drawn but which is used for path finding, collision detection etc.</li> </ul> <p>The natural next questio...
3
2009-03-25T12:55:11Z
[ "python" ]
Game map from Code
681,310
<p>It's a long one so you might want to get that cup of tea/coffee you've been holding off on ;)</p> <p>I run a game called World of Arl, it's a turn based strategy game akin to Risk or Diplomacy. Each player has a set of cities, armies and whatnot. The question revolves around the display of these things. Currently t...
2
2009-03-25T12:16:19Z
681,449
<p>Asuming the map is fixed (not created on the fly) its "correct" to use a bitmap as graphical representation - you want to make it as pretty as possible.</p> <p>For any game related features such as pathfinding or whatever fancy stuff you want to add you should add adequate data structures, even if that means some d...
1
2009-03-25T12:55:45Z
[ "python" ]
Nullable ForeignKeys and deleting a referenced model instance
681,497
<p>I have a ForeignKey which can be null in my model to model a loose coupling between the models. It looks somewhat like that:</p> <pre><code>class Message(models.Model): sender = models.ForeignKey(User, null=True, blank=True) sender_name = models.CharField(max_length=255) </code></pre> <p>On save the senders na...
7
2009-03-25T13:06:42Z
681,614
<p>Django does indeed emulate SQL's <code>ON DELETE CASCADE</code> behaviour, and there's no out-of-the box documented way to change this. The docs where they mention this are near the end of this section: <a href="http://docs.djangoproject.com/en/dev/topics/db/queries/#deleting-objects">Deleting objects</a>.</p> <p>Y...
13
2009-03-25T13:31:54Z
[ "python", "django", "django-models" ]
Nullable ForeignKeys and deleting a referenced model instance
681,497
<p>I have a ForeignKey which can be null in my model to model a loose coupling between the models. It looks somewhat like that:</p> <pre><code>class Message(models.Model): sender = models.ForeignKey(User, null=True, blank=True) sender_name = models.CharField(max_length=255) </code></pre> <p>On save the senders na...
7
2009-03-25T13:06:42Z
5,663,303
<p>Having just discovered the ON DELETE CASCADE behaviour myself, I see that in Django 1.3 they have made the foreign key behaviour <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.on_delete" rel="nofollow">configurable</a>.</p>
0
2011-04-14T12:34:43Z
[ "python", "django", "django-models" ]
How do you deploy django applications for windows?
681,565
<p>I'm working on a web application using <a href="http://code.google.com/p/isapi-wsgi/">isapi_wsgi</a> and <a href="http://code.google.com/p/django-pyodbc/">django-pyodbc</a>. I'd like to have a way to install all dependencies and push the files out to the webserver. Unfortunately, some of these are easier said than...
7
2009-03-25T13:22:36Z
681,642
<p>Have you looked into <a href="http://www.blueskyonmars.com/projects/paver/index.html" rel="nofollow">Paver</a>? It might not be the perfect solution, but maybe better then your current process.</p> <p>And it has setuptools (and other useful wrappers) built-in.</p>
3
2009-03-25T13:38:03Z
[ "python", "django", "iis", "deployment", "isapi-wsgi" ]
How do you deploy django applications for windows?
681,565
<p>I'm working on a web application using <a href="http://code.google.com/p/isapi-wsgi/">isapi_wsgi</a> and <a href="http://code.google.com/p/django-pyodbc/">django-pyodbc</a>. I'd like to have a way to install all dependencies and push the files out to the webserver. Unfortunately, some of these are easier said than...
7
2009-03-25T13:22:36Z
7,002,089
<p>BitNami provides free <a href="http://bitnami.org/stack/djangostack">Windows Django all-in-one installers</a> that include all dependencies to deploy a Django app on Windows. Disclaimer: I am one of the developers of this tool. If you are going for a hosted version, we also have free Windows Amazon Machine Images (l...
6
2011-08-09T19:51:46Z
[ "python", "django", "iis", "deployment", "isapi-wsgi" ]
How is string.find implemented in CPython?
681,649
<p>I was wondering if the 'find' method on strings was implemented with a linear search, or if python did something more sophisticated. The Python documentation doesn't discuss implementation details, so <a href="http://docs.python.org/library/stdtypes.html">http://docs.python.org/library/stdtypes.html</a> is of no hel...
6
2009-03-25T13:41:42Z
681,666
<p>I suppose so:</p> <blockquote> <p><a href="http://svn.python.org/view/python/trunk/Objects/stringlib/fastsearch.h?revision=68811&amp;view=markup">fast search/count implementation, based on a mix between boyer-moore and horspool, with a few more bells and whistles on the top</a></p> </blockquote>
15
2009-03-25T13:49:00Z
[ "python" ]
How is string.find implemented in CPython?
681,649
<p>I was wondering if the 'find' method on strings was implemented with a linear search, or if python did something more sophisticated. The Python documentation doesn't discuss implementation details, so <a href="http://docs.python.org/library/stdtypes.html">http://docs.python.org/library/stdtypes.html</a> is of no hel...
6
2009-03-25T13:41:42Z
681,668
<p>You should be able to find it in Objects/stringlib/find.h, although the real code is in fastsearch.h.</p>
4
2009-03-25T13:49:25Z
[ "python" ]
How is string.find implemented in CPython?
681,649
<p>I was wondering if the 'find' method on strings was implemented with a linear search, or if python did something more sophisticated. The Python documentation doesn't discuss implementation details, so <a href="http://docs.python.org/library/stdtypes.html">http://docs.python.org/library/stdtypes.html</a> is of no hel...
6
2009-03-25T13:41:42Z
681,884
<p>Looks like the algorithm used originates from <a href="http://en.wikipedia.org/wiki/Boyer%E2%80%93Moore%E2%80%93Horspool%5Falgorithm" rel="nofollow">Boyer-Moore-Horspool algorithm</a></p>
1
2009-03-25T14:40:26Z
[ "python" ]
Any alternatives to IronPython, Python for .NET for accessing CLR from python?
681,853
<p>Are there any alternatives to Python for .NET or IronPython for accessing .NET CLR? Both of these seem to have downsides in that Python for .NET is not under active development (as far as I can tell) and you lose some features available in CPython if you use IronPython. So are there any alternatives?</p>
3
2009-03-25T14:33:55Z
681,865
<p>What feature are you missing? There is a project called <a href="http://code.google.com/p/ironclad/" rel="nofollow">IronClad</a> that is helping to open access to CPython extensions from IronPython, it may be helpful. </p>
1
2009-03-25T14:36:19Z
[ ".net", "python", "clr", "ironpython" ]
Any alternatives to IronPython, Python for .NET for accessing CLR from python?
681,853
<p>Are there any alternatives to Python for .NET or IronPython for accessing .NET CLR? Both of these seem to have downsides in that Python for .NET is not under active development (as far as I can tell) and you lose some features available in CPython if you use IronPython. So are there any alternatives?</p>
3
2009-03-25T14:33:55Z
681,875
<p>As far as I know you are not going to get anything more actively developed than IronPython .</p> <p>IronPython is currently one of the .NET 5 being developed by the language team (C#, VB.NET, F#, IronPython and IronRuby) so I doubt that there's another open source .NET Python project that's gone anywhere near as fa...
1
2009-03-25T14:37:52Z
[ ".net", "python", "clr", "ironpython" ]
Any alternatives to IronPython, Python for .NET for accessing CLR from python?
681,853
<p>Are there any alternatives to Python for .NET or IronPython for accessing .NET CLR? Both of these seem to have downsides in that Python for .NET is not under active development (as far as I can tell) and you lose some features available in CPython if you use IronPython. So are there any alternatives?</p>
3
2009-03-25T14:33:55Z
682,313
<p>Apart from Python for .NET (which works pretty well for me), the only other solution I'm aware of is exposing the .NET libraries via COM interop, so you can use them via the pywin32 extensions. </p> <p>(I don't know much about .NET com interop yet, so hopefully someone else can provide further explanation on that.)...
3
2009-03-25T16:12:25Z
[ ".net", "python", "clr", "ironpython" ]
Any alternatives to IronPython, Python for .NET for accessing CLR from python?
681,853
<p>Are there any alternatives to Python for .NET or IronPython for accessing .NET CLR? Both of these seem to have downsides in that Python for .NET is not under active development (as far as I can tell) and you lose some features available in CPython if you use IronPython. So are there any alternatives?</p>
3
2009-03-25T14:33:55Z
685,825
<p>Well it's a python derivative, but you always have <a href="http://boo.codehaus.org" rel="nofollow">Boo</a>.</p>
1
2009-03-26T13:36:59Z
[ ".net", "python", "clr", "ironpython" ]
Python Class Decorator
681,953
<p>In Python 2.5, is there a way to create a decorator that decorates a class? Specifically, I want to use a decorator to add a member to a class and change the constructor to take a value for that member.</p> <p>Looking for something like the following (which has a syntax error on 'class Foo:':</p> <pre><code>def g...
89
2009-03-25T14:52:02Z
681,999
<p>That's not a good practice and there is no mechanism to do that because of that. The right way to accomplish what you want is inheritance.</p> <p>Take a look into the <a href="http://docs.python.org/tutorial/classes.html#inheritance" rel="nofollow">class documentation</a>.</p> <p>A little example:</p> <pre><code>...
11
2009-03-25T15:01:38Z
[ "python", "decorator", "python-2.5" ]
Python Class Decorator
681,953
<p>In Python 2.5, is there a way to create a decorator that decorates a class? Specifically, I want to use a decorator to add a member to a class and change the constructor to take a value for that member.</p> <p>Looking for something like the following (which has a syntax error on 'class Foo:':</p> <pre><code>def g...
89
2009-03-25T14:52:02Z
682,052
<p>I would second the notion that you may wish to consider a subclass instead of the approach you've outlined. However, not knowing your specific scenario, YMMV :-)</p> <p>What you're thinking of is a metaclass. The <code>__new__</code> function in a metaclass is passed the full proposed definition of the class, which...
62
2009-03-25T15:14:34Z
[ "python", "decorator", "python-2.5" ]
Python Class Decorator
681,953
<p>In Python 2.5, is there a way to create a decorator that decorates a class? Specifically, I want to use a decorator to add a member to a class and change the constructor to take a value for that member.</p> <p>Looking for something like the following (which has a syntax error on 'class Foo:':</p> <pre><code>def g...
89
2009-03-25T14:52:02Z
682,242
<p>Apart from the question whether class decorators are the right solution to your problem:</p> <p>in Python 2.6 and higher, there are class decorators with the @-syntax, so you can write:</p> <pre><code>@addID class Foo: pass </code></pre> <p>in older versions, you can do it another way:</p> <pre><code>class F...
168
2009-03-25T15:58:22Z
[ "python", "decorator", "python-2.5" ]
Python Class Decorator
681,953
<p>In Python 2.5, is there a way to create a decorator that decorates a class? Specifically, I want to use a decorator to add a member to a class and change the constructor to take a value for that member.</p> <p>Looking for something like the following (which has a syntax error on 'class Foo:':</p> <pre><code>def g...
89
2009-03-25T14:52:02Z
14,564,863
<p>There's actually a pretty good implementation of a class decorator here:</p> <p><a href="https://github.com/agiliq/Django-parsley/blob/master/parsley/decorators.py" rel="nofollow">https://github.com/agiliq/Django-parsley/blob/master/parsley/decorators.py</a></p> <p>I actually think this is a pretty interesting imp...
3
2013-01-28T15:05:42Z
[ "python", "decorator", "python-2.5" ]
Python Class Decorator
681,953
<p>In Python 2.5, is there a way to create a decorator that decorates a class? Specifically, I want to use a decorator to add a member to a class and change the constructor to take a value for that member.</p> <p>Looking for something like the following (which has a syntax error on 'class Foo:':</p> <pre><code>def g...
89
2009-03-25T14:52:02Z
18,938,008
<p>no-one has explained that you can dynamically define classes. so you can have a decorator that defines (and returns) a subclass:</p> <pre><code>def addId(cls): class AddId(cls): def __init__(self, id, *args, **kargs): super(AddId, self).__init__(*args, **kargs) self.__id = id ...
8
2013-09-21T21:47:44Z
[ "python", "decorator", "python-2.5" ]
Which version of python added the else clause for for loops?
682,185
<p>Which was the first version of python to include the <a href="http://docs.python.org/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops">else clause for for loops</a>? </p> <p>I find that the python docs usually does a good job of documenting when features were added, but I can't seem...
11
2009-03-25T15:48:24Z
682,234
<p>It's been around since at least <a href="http://www.python.org/doc/1.4/ref/ref7.html#HDR2" rel="nofollow">1.4</a>, which is the <a href="http://www.python.org/doc/versions/" rel="nofollow">oldest version of the documentation</a> I know of.</p>
7
2009-03-25T15:57:15Z
[ "python", "for-loop" ]
Which version of python added the else clause for for loops?
682,185
<p>Which was the first version of python to include the <a href="http://docs.python.org/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops">else clause for for loops</a>? </p> <p>I find that the python docs usually does a good job of documenting when features were added, but I can't seem...
11
2009-03-25T15:48:24Z
684,134
<p>It's been present since the beginning. To see that, get the source from alt.sources, specifically the message titled "<a href="http://groups.google.com/group/alt.sources/browse_thread/thread/74a577bbcfc4be0a/cbaaec4fbfebbbb6">Python 0.9.1 part 17/21</a>". The date is Feb 21, 1991. This post included the grammar defi...
28
2009-03-26T01:05:03Z
[ "python", "for-loop" ]
Which version of python added the else clause for for loops?
682,185
<p>Which was the first version of python to include the <a href="http://docs.python.org/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops">else clause for for loops</a>? </p> <p>I find that the python docs usually does a good job of documenting when features were added, but I can't seem...
11
2009-03-25T15:48:24Z
688,289
<p>Since version 1.0.1, at least..</p> <pre><code>Python 1.0.1 (Mar 27 2009) Copyright 1991-1994 Stichting Mathematisch Centrum, Amsterdam &gt;&gt;&gt; for x in range(2): ... print x ... else: ... print "loop done" ... 0 1 loop done </code></pre>
1
2009-03-27T02:11:14Z
[ "python", "for-loop" ]
Splitting out the output of ps using Python
682,446
<p>On Linux, the command ps aux outputs a list of processes with multiple columns for each stat. e.g.</p> <pre><code>USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND ... postfix 22611 0.0 0.2 54136 2544 ? S 15:26 0:00 pickup -l -t fifo -u apache 22920 0.0 1.5 198340 16588 ?...
9
2009-03-25T16:50:57Z
682,464
<p>Use the second parameter to <code>split</code> which specifies the maximum number of fields to split the string into. I guess you can find the number by counting the number of fields in the first line, i.e. the column titles.</p> <pre><code>ps = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE).communicate()[...
19
2009-03-25T16:53:31Z
[ "python", "regex", "linux" ]
Splitting out the output of ps using Python
682,446
<p>On Linux, the command ps aux outputs a list of processes with multiple columns for each stat. e.g.</p> <pre><code>USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND ... postfix 22611 0.0 0.2 54136 2544 ? S 15:26 0:00 pickup -l -t fifo -u apache 22920 0.0 1.5 198340 16588 ?...
9
2009-03-25T16:50:57Z
682,471
<p>The <code>maxsplit</code> optional argument to the <code>split</code> method might help you:</p> <pre><code>sep.split.(row, maxsplit=42) </code></pre>
1
2009-03-25T16:54:15Z
[ "python", "regex", "linux" ]
Splitting out the output of ps using Python
682,446
<p>On Linux, the command ps aux outputs a list of processes with multiple columns for each stat. e.g.</p> <pre><code>USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND ... postfix 22611 0.0 0.2 54136 2544 ? S 15:26 0:00 pickup -l -t fifo -u apache 22920 0.0 1.5 198340 16588 ?...
9
2009-03-25T16:50:57Z
682,487
<p>Why don't you use <a href="https://pypi.python.org/pypi/PSI/" rel="nofollow">PSI</a> instead? PSI provides process information on Linux and other Unix variants.</p> <pre><code>import psi.process for p in psi.process.ProcessTable().values(): … </code></pre>
4
2009-03-25T16:57:08Z
[ "python", "regex", "linux" ]
Splitting out the output of ps using Python
682,446
<p>On Linux, the command ps aux outputs a list of processes with multiple columns for each stat. e.g.</p> <pre><code>USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND ... postfix 22611 0.0 0.2 54136 2544 ? S 15:26 0:00 pickup -l -t fifo -u apache 22920 0.0 1.5 198340 16588 ?...
9
2009-03-25T16:50:57Z
3,367,742
<p>Check out the <a href="http://pypi.python.org/pypi/psutil/" rel="nofollow">python.psutils</a> package.</p> <p><code>psutil.process_iter</code> returns a generator which you can use to iterate over all processes. <code>p.cmdline</code> is a list of each Process object's cmdline arguments, separated just the way you ...
11
2010-07-29T23:27:40Z
[ "python", "regex", "linux" ]
Splitting out the output of ps using Python
682,446
<p>On Linux, the command ps aux outputs a list of processes with multiple columns for each stat. e.g.</p> <pre><code>USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND ... postfix 22611 0.0 0.2 54136 2544 ? S 15:26 0:00 pickup -l -t fifo -u apache 22920 0.0 1.5 198340 16588 ?...
9
2009-03-25T16:50:57Z
10,490,104
<p>Here's a nice routine and usage to get you going:</p> <pre><code>def getProcessData(): ps = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE).communicate()[0] processes = ps.split('\n') # this specifies the number of splits, so the splitted lines # will have (nfields+1) elements nfields = ...
1
2012-05-07T22:38:41Z
[ "python", "regex", "linux" ]
What is a clean, pythonic way to have multiple constructors in Python?
682,504
<p>I can't find a definitive answer for this. AFAIK, you can't have multiple <code>__init__</code> functions in a Python class. So what is a good way to solve this problem? </p> <p>Suppose I have an class called <code>Cheese</code> with the <code>number_of_holes</code> property. How can I have two ways of creating che...
385
2009-03-25T17:00:21Z
682,513
<p>Actually <code>None</code> is much better for "magic" values:</p> <pre><code>class Cheese(): def __init__(self, num_holes = None): if num_holes is None: ... </code></pre> <p>Now if you want complete freedom of adding more parameters:</p> <pre><code>class Cheese(): def __init__(self, *a...
542
2009-03-25T17:03:38Z
[ "coding-style", "python" ]
What is a clean, pythonic way to have multiple constructors in Python?
682,504
<p>I can't find a definitive answer for this. AFAIK, you can't have multiple <code>__init__</code> functions in a Python class. So what is a good way to solve this problem? </p> <p>Suppose I have an class called <code>Cheese</code> with the <code>number_of_holes</code> property. How can I have two ways of creating che...
385
2009-03-25T17:00:21Z
682,514
<p>Use <code>num_holes=None</code> as a default, instead. Then check for whether <code>num_holes is None</code>, and if so, randomize. That's what I generally see, anyway.</p> <p>More radically different construction methods may warrant a classmethod that returns an instance of <code>cls</code>.</p>
6
2009-03-25T17:03:56Z
[ "coding-style", "python" ]
What is a clean, pythonic way to have multiple constructors in Python?
682,504
<p>I can't find a definitive answer for this. AFAIK, you can't have multiple <code>__init__</code> functions in a Python class. So what is a good way to solve this problem? </p> <p>Suppose I have an class called <code>Cheese</code> with the <code>number_of_holes</code> property. How can I have two ways of creating che...
385
2009-03-25T17:00:21Z
682,545
<p>Using <code>num_holes=None</code> as the default is fine if you are going to have just <code>__init__</code>.</p> <p>If you want multiple, independent "constructors", you can provide these as class methods. These are usually called factory methods. In this case you could have the default for <code>num_holes</code>...
356
2009-03-25T17:11:24Z
[ "coding-style", "python" ]
What is a clean, pythonic way to have multiple constructors in Python?
682,504
<p>I can't find a definitive answer for this. AFAIK, you can't have multiple <code>__init__</code> functions in a Python class. So what is a good way to solve this problem? </p> <p>Suppose I have an class called <code>Cheese</code> with the <code>number_of_holes</code> property. How can I have two ways of creating che...
385
2009-03-25T17:00:21Z
682,546
<p>Why do you think your solution is "clunky"? Personally I would prefer one constructor with default values over multiple overloaded constructors in situations like yours (Python does not support method overloading anyway):</p> <pre><code>def __init__(self, num_holes=None): if num_holes is None: # Constru...
14
2009-03-25T17:11:35Z
[ "coding-style", "python" ]
What is a clean, pythonic way to have multiple constructors in Python?
682,504
<p>I can't find a definitive answer for this. AFAIK, you can't have multiple <code>__init__</code> functions in a Python class. So what is a good way to solve this problem? </p> <p>Suppose I have an class called <code>Cheese</code> with the <code>number_of_holes</code> property. How can I have two ways of creating che...
385
2009-03-25T17:00:21Z
682,563
<p>All of these answers are excellent if you want to use optional parameters, but another Pythonic possibility is to use a classmethod to generate a factory-style pseudo-constructor:</p> <pre><code>def __init__(self, num_holes): # do stuff with the number @classmethod def fromRandom(cls): return cls( # some-ran...
13
2009-03-25T17:16:04Z
[ "coding-style", "python" ]
What is a clean, pythonic way to have multiple constructors in Python?
682,504
<p>I can't find a definitive answer for this. AFAIK, you can't have multiple <code>__init__</code> functions in a Python class. So what is a good way to solve this problem? </p> <p>Suppose I have an class called <code>Cheese</code> with the <code>number_of_holes</code> property. How can I have two ways of creating che...
385
2009-03-25T17:00:21Z
683,155
<p>The best answer is the one above about default arguments, but I had fun writing this, and it certainly does fit the bill for "multiple constructors". Use at your own risk.</p> <p>What about the <a href="http://docs.python.org/reference/datamodel.html#object.%5F%5Fnew%5F%5F"><strong>new</strong></a> method.</p> <p>...
8
2009-03-25T19:48:35Z
[ "coding-style", "python" ]
What is a clean, pythonic way to have multiple constructors in Python?
682,504
<p>I can't find a definitive answer for this. AFAIK, you can't have multiple <code>__init__</code> functions in a Python class. So what is a good way to solve this problem? </p> <p>Suppose I have an class called <code>Cheese</code> with the <code>number_of_holes</code> property. How can I have two ways of creating che...
385
2009-03-25T17:00:21Z
7,891,419
<p>Those are good ideas for your implementation, but if you are presenting a cheese making interface to a user. They don't care how many holes the cheese has or what internals go into making cheese. The user of your code just wants "gouda" or "parmesean" right?</p> <p>So why not do this:</p> <pre><code># cheese_use...
11
2011-10-25T15:06:03Z
[ "coding-style", "python" ]
What is a clean, pythonic way to have multiple constructors in Python?
682,504
<p>I can't find a definitive answer for this. AFAIK, you can't have multiple <code>__init__</code> functions in a Python class. So what is a good way to solve this problem? </p> <p>Suppose I have an class called <code>Cheese</code> with the <code>number_of_holes</code> property. How can I have two ways of creating che...
385
2009-03-25T17:00:21Z
29,919,666
<p>I'd use inheritance. Especially if there are going to be more differences than number of holes. Especially if Gouda will need to have different set of members then Parmesan.</p> <pre><code>class Gouda(Cheese): def __init__(self): super(Gouda).__init__(num_holes=10) class Parmesan(Cheese): def __in...
2
2015-04-28T12:33:56Z
[ "coding-style", "python" ]
What is a clean, pythonic way to have multiple constructors in Python?
682,504
<p>I can't find a definitive answer for this. AFAIK, you can't have multiple <code>__init__</code> functions in a Python class. So what is a good way to solve this problem? </p> <p>Suppose I have an class called <code>Cheese</code> with the <code>number_of_holes</code> property. How can I have two ways of creating che...
385
2009-03-25T17:00:21Z
33,545,167
<h3><a href="https://groups.google.com/forum/#!searchin/comp.lang.python/Re$3A$20Multiple$20constructors%22$20by$20Alex$20Martelli/comp.lang.python/E86OghKdggc/rtokcAhE1JkJ" rel="nofollow">Text from Alex Martelli</a></h3> <p>(as mentioned by <a href="http://stackoverflow.com/questions/682504/what-is-a-clean-pythonic-w...
2
2015-11-05T12:57:06Z
[ "coding-style", "python" ]
What is a clean, pythonic way to have multiple constructors in Python?
682,504
<p>I can't find a definitive answer for this. AFAIK, you can't have multiple <code>__init__</code> functions in a Python class. So what is a good way to solve this problem? </p> <p>Suppose I have an class called <code>Cheese</code> with the <code>number_of_holes</code> property. How can I have two ways of creating che...
385
2009-03-25T17:00:21Z
38,885,481
<p>One should definitely prefer the solutions already posted, but since no one mentioned this solution yet, I think it is worth mentioning for completeness.</p> <p>The <code>@classmethod</code> approach can be modified to provide an alternative constructor which does not invoke the default constructor (<code>__init__<...
0
2016-08-11T00:20:55Z
[ "coding-style", "python" ]
Python Virtual Machine architecture diagrams/references
682,675
<p>Someone could point out sites/books where I can find introductory documentation about the architecture of the Python VM? </p> <p>I'm interested in the C version, but if there are easy-to-follow references about other implementations it could be helpful too.</p> <p>I'm trying to find any kind of resources of higher...
10
2009-03-25T17:42:49Z
682,897
<p>You should be able to find the information you need at <a href="http://svn.python.org/view/python/trunk/Python/ceval.c?view=markup" rel="nofollow">http://svn.python.org/view/python/trunk/Python/ceval.c?view=markup</a></p> <p>If that's too low level for you, try</p> <ul> <li><a href="http://www.python.org/dev/peps/...
9
2009-03-25T18:36:39Z
[ "python", "architecture", "language-design", "vm-implementation" ]
Python Desktop Integration - Drag and drop
682,692
<p>I have a pygame window that I want to know when a file has been dragged and dropped onto it. I only need to be able to fetch the name of the file. How can this be accomplished?</p>
3
2009-03-25T17:47:20Z
683,454
<p>Here's a <a href="http://mail.python.org/pipermail/python-win32/2008-April/007406.html" rel="nofollow">forum thread</a> that might be what you're looking for. </p> <p>And <a href="http://mail.python.org/pipermail/python-win32/2008-September/008209.html" rel="nofollow">another</a> forum.</p> <p>And a link to the <...
4
2009-03-25T21:06:32Z
[ "python", "drag-and-drop", "pygame", "desktop-integration" ]
Python Desktop Integration - Drag and drop
682,692
<p>I have a pygame window that I want to know when a file has been dragged and dropped onto it. I only need to be able to fetch the name of the file. How can this be accomplished?</p>
3
2009-03-25T17:47:20Z
3,887,565
<p>one option for a similar effect is is to use pygame's scrap module so you can copy-paste into the window, your program would just need to look for ctr-V events.</p> <p>On this XFCE desktop I'm using If I hit ctrl-C with a file selected, the file name shows up when I type </p> <pre><code>pygame.scrap.init() type...
0
2010-10-08T03:46:34Z
[ "python", "drag-and-drop", "pygame", "desktop-integration" ]
What to do with "The input line is too long" error message?
682,799
<p>I am trying to use os.system() to call another program that takes an input and an output file. The command I use is ~250 characters due to the long folder names. </p> <p>When I try to call the command, I'm getting an error: <code>The input line is too long</code>.</p> <p>I'm guessing there's a <code>255 character ...
10
2009-03-25T18:08:42Z
682,807
<p>Assuming you're using windows, from the backslashes, you could write a .bat file from python and then <code>os.system()</code> on that. It's a hack.</p>
1
2009-03-25T18:11:08Z
[ "python", "command-line", "windows-console" ]
What to do with "The input line is too long" error message?
682,799
<p>I am trying to use os.system() to call another program that takes an input and an output file. The command I use is ~250 characters due to the long folder names. </p> <p>When I try to call the command, I'm getting an error: <code>The input line is too long</code>.</p> <p>I'm guessing there's a <code>255 character ...
10
2009-03-25T18:08:42Z
682,815
<p>Make sure when you're using '\' in your strings that they're being properly escaped.</p> <p>Python uses the '\' as the escape character, so the string <code>"..\folder\filename"</code> evaluates to <code>"..folderfilename"</code> since an escaped f is still an f.</p> <p>You probably want to use</p> <pre><code>r"....
1
2009-03-25T18:13:55Z
[ "python", "command-line", "windows-console" ]