title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Why does namespace after method call changes? | 1,361,393 | <p>I'm creating a class, but having some trouble with the namespacing in python.</p>
<p>You can see the code below, and it mostly works ok, but after the call to <code>guiFrame._stateMachine()</code> the time module is somehow not defined anymore.</p>
<p>If I re-import the time module in <code>_stateMachine()</code> ... | 2 | 2009-09-01T09:07:54Z | 1,361,409 | <p>Why do you assign to <code>time</code>? You can't use it as local variable, it will overshadow the module! If you look closely it complains that you use <code>time</code> before you assign to it -- since to use it as a local variable in <code>_stateMachine</code>.</p>
<pre><code>time = 4
</code></pre>
| 7 | 2009-09-01T09:11:58Z | [
"python",
"namespaces"
] |
Why does namespace after method call changes? | 1,361,393 | <p>I'm creating a class, but having some trouble with the namespacing in python.</p>
<p>You can see the code below, and it mostly works ok, but after the call to <code>guiFrame._stateMachine()</code> the time module is somehow not defined anymore.</p>
<p>If I re-import the time module in <code>_stateMachine()</code> ... | 2 | 2009-09-01T09:07:54Z | 1,361,411 | <p>You seem to use time as a variable. What happens here:</p>
<blockquote>
<p>"C:\Scripts\Python\GUI.py", line 74</p>
</blockquote>
| 2 | 2009-09-01T09:12:24Z | [
"python",
"namespaces"
] |
Why does namespace after method call changes? | 1,361,393 | <p>I'm creating a class, but having some trouble with the namespacing in python.</p>
<p>You can see the code below, and it mostly works ok, but after the call to <code>guiFrame._stateMachine()</code> the time module is somehow not defined anymore.</p>
<p>If I re-import the time module in <code>_stateMachine()</code> ... | 2 | 2009-09-01T09:07:54Z | 1,361,424 | <p>You try to assing to the variable <code>time</code> in this method:</p>
<pre><code>time = 4
</code></pre>
<p>Therefore the compiler assumes that time must be a local variable, which isn't true. And that is the reason why you get this error when you want to use the module <code>time</code>, even if you try to use t... | 2 | 2009-09-01T09:14:57Z | [
"python",
"namespaces"
] |
How to encode UTF8 filename for HTTP headers? (Python, Django) | 1,361,604 | <p>I have problem with HTTP headers, they're encoded in ASCII and I want to provided a view for downloading files that names can be non ASCII. </p>
<pre><code>response['Content-Disposition'] = 'attachment; filename="%s"' % (vo.filename.encode("ASCII","replace"), )
</code></pre>
<p>I don't want to use static files ser... | 38 | 2009-09-01T10:00:31Z | 1,361,646 | <p>This is a FAQ.</p>
<p>There is no interoperable way to do this. Some browsers implement proprietary extensions (IE, Chrome), other implement RFC 2231 (Firefox, Opera).</p>
<p>See test cases at <a href="http://greenbytes.de/tech/tc2231/">http://greenbytes.de/tech/tc2231/</a>.</p>
<p>Update: as of November 2012, al... | 35 | 2009-09-01T10:11:28Z | [
"python",
"django",
"http",
"http-headers",
"escaping"
] |
How to encode UTF8 filename for HTTP headers? (Python, Django) | 1,361,604 | <p>I have problem with HTTP headers, they're encoded in ASCII and I want to provided a view for downloading files that names can be non ASCII. </p>
<pre><code>response['Content-Disposition'] = 'attachment; filename="%s"' % (vo.filename.encode("ASCII","replace"), )
</code></pre>
<p>I don't want to use static files ser... | 38 | 2009-09-01T10:00:31Z | 1,362,846 | <p>Take a look at this snippets to encode non ascii filenames <a href="http://www.djangosnippets.org/snippets/1710/" rel="nofollow">http://www.djangosnippets.org/snippets/1710/</a></p>
| 1 | 2009-09-01T14:37:20Z | [
"python",
"django",
"http",
"http-headers",
"escaping"
] |
How to encode UTF8 filename for HTTP headers? (Python, Django) | 1,361,604 | <p>I have problem with HTTP headers, they're encoded in ASCII and I want to provided a view for downloading files that names can be non ASCII. </p>
<pre><code>response['Content-Disposition'] = 'attachment; filename="%s"' % (vo.filename.encode("ASCII","replace"), )
</code></pre>
<p>I don't want to use static files ser... | 38 | 2009-09-01T10:00:31Z | 1,365,186 | <p>Don't send a filename in Content-Disposition. There is no way to make non-ASCII header parameters work cross-browser(*).</p>
<p>Instead, send just âContent-Disposition: attachmentâ, and leave the filename as a URL-encoded UTF-8 string in the trailing (PATH_INFO) part of your URL, for the browser to pick up and ... | 30 | 2009-09-01T23:41:27Z | [
"python",
"django",
"http",
"http-headers",
"escaping"
] |
How to encode UTF8 filename for HTTP headers? (Python, Django) | 1,361,604 | <p>I have problem with HTTP headers, they're encoded in ASCII and I want to provided a view for downloading files that names can be non ASCII. </p>
<pre><code>response['Content-Disposition'] = 'attachment; filename="%s"' % (vo.filename.encode("ASCII","replace"), )
</code></pre>
<p>I don't want to use static files ser... | 38 | 2009-09-01T10:00:31Z | 3,144,680 | <p>A hack:</p>
<pre><code>if (Request.UserAgent.Contains("IE"))
{
// IE will accept URL encoding, but spaces don't need to be, and since they're so common..
filename = filename.Replace("%", "%25").Replace(";", "%3B").Replace("#", "%23").Replace("&", "%26");
}
</code></pre>
| 0 | 2010-06-29T20:58:53Z | [
"python",
"django",
"http",
"http-headers",
"escaping"
] |
How to encode UTF8 filename for HTTP headers? (Python, Django) | 1,361,604 | <p>I have problem with HTTP headers, they're encoded in ASCII and I want to provided a view for downloading files that names can be non ASCII. </p>
<pre><code>response['Content-Disposition'] = 'attachment; filename="%s"' % (vo.filename.encode("ASCII","replace"), )
</code></pre>
<p>I don't want to use static files ser... | 38 | 2009-09-01T10:00:31Z | 8,996,249 | <p>Note that in 2011, <a href="http://tools.ietf.org/html/rfc6266#appendix-D">RFC 6266</a> (especially Appendix D) weighed in on this issue and has specific recommendations to follow.</p>
<p>Namely, you can issue a <code>filename</code> with only ASCII characters, followed by <code>filename*</code> with a RFC 5987-for... | 22 | 2012-01-25T00:13:54Z | [
"python",
"django",
"http",
"http-headers",
"escaping"
] |
IMAP interface access to existing user messaging system in Python | 1,361,671 | <p>I am running a site where users can private message each other. As with any other such website, to read and mark their messages, users must log on to the site.</p>
<p>I wish to expose an IMAP interface so that users may read their site messages using their standard email client. There would be few complications in ... | 0 | 2009-09-01T10:18:14Z | 1,361,689 | <p><a href="http://twistedmatrix.com/trac/wiki/TwistedMail" rel="nofollow">Twisted Mail</a> project:</p>
<blockquote>
<p>Twisted Mail contains high-level, efficient protocol implementations for both clients and servers of SMTP, POP3, and <strong>IMAP4</strong>. Additionally, it contains an "out of the box" combinati... | 1 | 2009-09-01T10:22:20Z | [
"python",
"interface",
"imap"
] |
Cubic root of the negative number on python | 1,361,740 | <p>Can someone help me to find a solution on how to calculate a cubic root of the negative number using python?</p>
<pre><code>>>> math.pow(-3, float(1)/3)
nan
</code></pre>
<p>it does not work. Cubic root of the negative number is negative number. Any solutions?</p>
| 11 | 2009-09-01T10:40:10Z | 1,361,750 | <p>You could use:</p>
<pre><code>-math.pow(3, float(1)/3)
</code></pre>
<p>Or more generally:</p>
<pre><code>if x > 0:
return math.pow(x, float(1)/3)
elif x < 0:
return -math.pow(abs(x), float(1)/3)
else:
return 0
</code></pre>
| 9 | 2009-09-01T10:42:37Z | [
"python",
"math"
] |
Cubic root of the negative number on python | 1,361,740 | <p>Can someone help me to find a solution on how to calculate a cubic root of the negative number using python?</p>
<pre><code>>>> math.pow(-3, float(1)/3)
nan
</code></pre>
<p>it does not work. Cubic root of the negative number is negative number. Any solutions?</p>
| 11 | 2009-09-01T10:40:10Z | 1,361,761 | <p>Primitive solution:</p>
<pre><code>def cubic_root(nr):
if nr<0:
return -math.pow(-nr, float(1)/3)
else:
return math.pow(nr, float(1)/3)
</code></pre>
<p>Probably massively non-pythonic, but it should work.</p>
| 0 | 2009-09-01T10:45:52Z | [
"python",
"math"
] |
Cubic root of the negative number on python | 1,361,740 | <p>Can someone help me to find a solution on how to calculate a cubic root of the negative number using python?</p>
<pre><code>>>> math.pow(-3, float(1)/3)
nan
</code></pre>
<p>it does not work. Cubic root of the negative number is negative number. Any solutions?</p>
| 11 | 2009-09-01T10:40:10Z | 1,361,778 | <pre><code>math.pow(abs(x),float(1)/3) * (1,-1)[x<0]
</code></pre>
| 10 | 2009-09-01T10:50:09Z | [
"python",
"math"
] |
Cubic root of the negative number on python | 1,361,740 | <p>Can someone help me to find a solution on how to calculate a cubic root of the negative number using python?</p>
<pre><code>>>> math.pow(-3, float(1)/3)
nan
</code></pre>
<p>it does not work. Cubic root of the negative number is negative number. Any solutions?</p>
| 11 | 2009-09-01T10:40:10Z | 1,361,789 | <p>Taking the earlier answers and making it into a one-liner:</p>
<pre><code>import math
def cubic_root(x):
return math.copysign(math.pow(abs(x), 1.0/3.0), x)
</code></pre>
| 8 | 2009-09-01T10:54:58Z | [
"python",
"math"
] |
Cubic root of the negative number on python | 1,361,740 | <p>Can someone help me to find a solution on how to calculate a cubic root of the negative number using python?</p>
<pre><code>>>> math.pow(-3, float(1)/3)
nan
</code></pre>
<p>it does not work. Cubic root of the negative number is negative number. Any solutions?</p>
| 11 | 2009-09-01T10:40:10Z | 1,361,794 | <p>You can also wrap the <code>libm</code> library that offers a <code>cbrt</code> (cube root) function:</p>
<pre><code>from ctypes import *
libm = cdll.LoadLibrary('libm.so.6')
libm.cbrt.restype = c_double
libm.cbrt.argtypes = [c_double]
libm.cbrt(-8.0)
</code></pre>
<p>gives the expected</p>
<pre><code>-2.0
</code... | 3 | 2009-09-01T10:56:29Z | [
"python",
"math"
] |
Cubic root of the negative number on python | 1,361,740 | <p>Can someone help me to find a solution on how to calculate a cubic root of the negative number using python?</p>
<pre><code>>>> math.pow(-3, float(1)/3)
nan
</code></pre>
<p>it does not work. Cubic root of the negative number is negative number. Any solutions?</p>
| 11 | 2009-09-01T10:40:10Z | 1,361,834 | <p>The cubic root of a negative number is just the negative of the cubic root of the absolute value of that number.</p>
<p>i.e. x^(1/3) for x < 0 is the same as (-1)*(|x|)^(1/3)</p>
<p>Just make your number positive, and then perform cubic root.</p>
| 3 | 2009-09-01T11:04:54Z | [
"python",
"math"
] |
Cubic root of the negative number on python | 1,361,740 | <p>Can someone help me to find a solution on how to calculate a cubic root of the negative number using python?</p>
<pre><code>>>> math.pow(-3, float(1)/3)
nan
</code></pre>
<p>it does not work. Cubic root of the negative number is negative number. Any solutions?</p>
| 11 | 2009-09-01T10:40:10Z | 1,362,288 | <p>A simple use of <a href="http://en.wikipedia.org/wiki/De%5FMoivre%27s%5Fformula">De Moivre's formula</a>, is sufficient to show that the cube root of a value, regardless of sign, is a multi-valued function. That means, for any input value, there will be three solutions. Most of the solutions presented to far only r... | 17 | 2009-09-01T12:44:15Z | [
"python",
"math"
] |
Cubic root of the negative number on python | 1,361,740 | <p>Can someone help me to find a solution on how to calculate a cubic root of the negative number using python?</p>
<pre><code>>>> math.pow(-3, float(1)/3)
nan
</code></pre>
<p>it does not work. Cubic root of the negative number is negative number. Any solutions?</p>
| 11 | 2009-09-01T10:40:10Z | 1,362,820 | <p>You can get the complete (all n roots) and more general (any sign, any power) solution using:</p>
<pre><code>import cmath
x, t = -3., 3 # x**(1/t)
a = cmath.exp((1./t)*cmath.log(x))
p = cmath.exp(1j*2*cmath.pi*(1./t))
r = [a*(p**i) for i in range(t)]
</code></pre>
<p>Explanation:
a is using the equation x<sup>... | 8 | 2009-09-01T14:31:59Z | [
"python",
"math"
] |
Cubic root of the negative number on python | 1,361,740 | <p>Can someone help me to find a solution on how to calculate a cubic root of the negative number using python?</p>
<pre><code>>>> math.pow(-3, float(1)/3)
nan
</code></pre>
<p>it does not work. Cubic root of the negative number is negative number. Any solutions?</p>
| 11 | 2009-09-01T10:40:10Z | 23,831,822 | <p>You can use <code>cbrt</code> from <code>scipy.special</code>:</p>
<pre><code>>>> from scipy.special import cbrt
>>> cbrt(-3)
-1.4422495703074083
</code></pre>
<p>This also works for arrays.</p>
| 0 | 2014-05-23T14:27:38Z | [
"python",
"math"
] |
Cubic root of the negative number on python | 1,361,740 | <p>Can someone help me to find a solution on how to calculate a cubic root of the negative number using python?</p>
<pre><code>>>> math.pow(-3, float(1)/3)
nan
</code></pre>
<p>it does not work. Cubic root of the negative number is negative number. Any solutions?</p>
| 11 | 2009-09-01T10:40:10Z | 30,122,775 | <p>I just had a very similar problem and found the NumPy solution from <a href="http://scipy-user.10969.n7.nabble.com/numpy-array-root-operation-td1727.html" rel="nofollow">this forum post</a>.</p>
<p>In a nushell, we can use of the NumPy <code>sign</code> and <code>absolute</code> methods to help us out. Here is an e... | 0 | 2015-05-08T11:31:17Z | [
"python",
"math"
] |
Cubic root of the negative number on python | 1,361,740 | <p>Can someone help me to find a solution on how to calculate a cubic root of the negative number using python?</p>
<pre><code>>>> math.pow(-3, float(1)/3)
nan
</code></pre>
<p>it does not work. Cubic root of the negative number is negative number. Any solutions?</p>
| 11 | 2009-09-01T10:40:10Z | 32,223,710 | <p>For an arithmetic, calculator-like answer in Python 3:</p>
<pre><code>>>> -3.0**(1/3)
-1.4422495703074083
</code></pre>
<p>or <code>-3.0**(1./3)</code> in Python 2.</p>
<p>For the algebraic solution of <code>x**3 + (0*x**2 + 0*x) + 3 = 0</code> use numpy:</p>
<pre><code>>>> p = [1,0,0,3]
>&g... | 0 | 2015-08-26T10:08:48Z | [
"python",
"math"
] |
Cubic root of the negative number on python | 1,361,740 | <p>Can someone help me to find a solution on how to calculate a cubic root of the negative number using python?</p>
<pre><code>>>> math.pow(-3, float(1)/3)
nan
</code></pre>
<p>it does not work. Cubic root of the negative number is negative number. Any solutions?</p>
| 11 | 2009-09-01T10:40:10Z | 33,182,838 | <p>this works with numpy array as well:</p>
<pre><code>cbrt = lambda n: n/abs(n)*abs(n)**(1./3)
</code></pre>
| 0 | 2015-10-17T04:45:48Z | [
"python",
"math"
] |
Can't use an inheriting Django model's Meta class to configure a field defined in an inherited abstract model | 1,361,791 | <p>I would like to use properties from an inheriting model's Meta class to configure a field defined in an abstract model higher up the inheritance tree:</p>
<pre><code>class NamedModel(models.Model):
class Meta:
abstract = True
verbose_name = 'object'
name = models.CharField("Name",
m... | 4 | 2009-09-01T10:55:43Z | 1,362,316 | <p>I think this happens because Meta.verbose_name is used and NamedModel.name is created when class NamedModel is parsed. So later, when class OwnedModel gets parsed, there is no chance to change anything.</p>
<p>Maybe you can set the help_text property on OwnedModel.name later on, but this may change NamedModel.name ... | 1 | 2009-09-01T12:51:15Z | [
"python",
"django",
"inheritance",
"django-models",
"metaclass"
] |
Can't use an inheriting Django model's Meta class to configure a field defined in an inherited abstract model | 1,361,791 | <p>I would like to use properties from an inheriting model's Meta class to configure a field defined in an abstract model higher up the inheritance tree:</p>
<pre><code>class NamedModel(models.Model):
class Meta:
abstract = True
verbose_name = 'object'
name = models.CharField("Name",
m... | 4 | 2009-09-01T10:55:43Z | 1,363,176 | <p>In fact I ended up doing the following. The base model gets given a dynamic_field_definition() class method, which can be used to patch up the fields, with the cls argument being the correct (inheriting) class. That means that that cls' Meta attributes are of that correct child, not the original base.</p>
<p>I then... | 0 | 2009-09-01T15:40:27Z | [
"python",
"django",
"inheritance",
"django-models",
"metaclass"
] |
Can't use an inheriting Django model's Meta class to configure a field defined in an inherited abstract model | 1,361,791 | <p>I would like to use properties from an inheriting model's Meta class to configure a field defined in an abstract model higher up the inheritance tree:</p>
<pre><code>class NamedModel(models.Model):
class Meta:
abstract = True
verbose_name = 'object'
name = models.CharField("Name",
m... | 4 | 2009-09-01T10:55:43Z | 37,395,779 | <p>Why don't you try to make a class.</p>
<pre><code>class BaseNamedModelMeta:
abstract = True
verbose_name = "your text"
</code></pre>
<p>And then inherit and override whatever you want like this:</p>
<pre><code>class OwnedModel(NamedModel):
class Meta(BaseNamedModelMeta):
verbose_name = 'owned ... | 2 | 2016-05-23T16:10:51Z | [
"python",
"django",
"inheritance",
"django-models",
"metaclass"
] |
How to unload a .NET assembly reference in IronPython | 1,362,114 | <p>After loading a reference to an assembly with something like:</p>
<pre><code>import clr
clr.AddRferenceToFileAndPath(r'C:\foo.dll')
</code></pre>
<p>How can I unload the assembly again?</p>
<p>Why would anyone ever want to do this? Because I'm recompiling <code>foo.dll</code> and want to reload it, but the compil... | 5 | 2009-09-01T12:03:01Z | 1,362,144 | <p>.NET itself doesn't support unloading just a single assembly. Instead, you need to unload a whole <code>AppDomain</code>. I don't know exactly how IronPython works with <code>AppDomain</code>s, but that's the normal .NET way of doing things. (Load the assembly into a new <code>AppDomain</code>, use it, discard the <... | 4 | 2009-09-01T12:10:50Z | [
"python",
".net",
"ironpython",
"python.net"
] |
Django: how to retrieve an object selected by the ``object_detail`` generic view? | 1,362,782 | <p>Hi (sorry for my ugly english)</p>
<p>I wonder if this is possible to retrieve an object which was selected with the object_detail generic view. For example :</p>
<p>from django.views.generic.list_detail import object_detail</p>
<pre><code>def my_view(request, slug)
response = object_detail(request, MyModel.o... | 1 | 2009-09-01T14:25:02Z | 1,363,107 | <p>You can't get the object this way, since <code>object_detail</code> simply returns a rendered response. If you need it, you'll just have to get it manually:</p>
<pre><code>object = MyModel.objects.get(slug=slug)
</code></pre>
| 2 | 2009-09-01T15:28:40Z | [
"python",
"django",
"view",
"generics"
] |
Encapsulation severely hurts performance? | 1,362,997 | <p>I know this question is kind of stupid, maybe it's a just a part of writing code but it seems defining simple functions can really hurt performance severely... I've tried this simple test:</p>
<pre><code>def make_legal_foo_string(x):
return "This is a foo string: " + str(x)
def sum_up_to(x):
return x*(x+1)... | 3 | 2009-09-01T15:09:44Z | 1,363,032 | <p>Figuring out what to make into a function and what to just include inline is something of an art. Many factors (performance, readability, maintainability) feed into the equation.</p>
<p>I actually find your example kind of silly in many ways - a function that just returns it's argument? Unless it's an overload that... | 0 | 2009-09-01T15:16:27Z | [
"python",
"performance"
] |
Encapsulation severely hurts performance? | 1,362,997 | <p>I know this question is kind of stupid, maybe it's a just a part of writing code but it seems defining simple functions can really hurt performance severely... I've tried this simple test:</p>
<pre><code>def make_legal_foo_string(x):
return "This is a foo string: " + str(x)
def sum_up_to(x):
return x*(x+1)... | 3 | 2009-09-01T15:09:44Z | 1,363,047 | <p>I don't know how good python compilers are, but the answer to this question for many languages is that the compiler will optimize calls to small procedures / functions / methods by inlining them. In fact, in some language implementations you generally get better performance by NOT trying to "micro-optimize" the cod... | 2 | 2009-09-01T15:17:45Z | [
"python",
"performance"
] |
Encapsulation severely hurts performance? | 1,362,997 | <p>I know this question is kind of stupid, maybe it's a just a part of writing code but it seems defining simple functions can really hurt performance severely... I've tried this simple test:</p>
<pre><code>def make_legal_foo_string(x):
return "This is a foo string: " + str(x)
def sum_up_to(x):
return x*(x+1)... | 3 | 2009-09-01T15:09:44Z | 1,363,064 | <p>Function call overheads are not big; you won't normally notice them. You only see them in this case because your actual code (x*x) is itself so completely trivial. In any real program that does real work, the amount of time spent in function-calling overhead will be negligably small.</p>
<p>(Not that I'd really rec... | 6 | 2009-09-01T15:20:03Z | [
"python",
"performance"
] |
Encapsulation severely hurts performance? | 1,362,997 | <p>I know this question is kind of stupid, maybe it's a just a part of writing code but it seems defining simple functions can really hurt performance severely... I've tried this simple test:</p>
<pre><code>def make_legal_foo_string(x):
return "This is a foo string: " + str(x)
def sum_up_to(x):
return x*(x+1)... | 3 | 2009-09-01T15:09:44Z | 1,363,071 | <p>What you are talking about is the effect of inlining functions for gaining efficiency. </p>
<p>It is certainly true in your Python example, that encapsulation hurts performance. But there are some counter example to it:</p>
<ol>
<li><p>In Java, defining getter&setter instead of defining public member variables... | 1 | 2009-09-01T15:21:30Z | [
"python",
"performance"
] |
Encapsulation severely hurts performance? | 1,362,997 | <p>I know this question is kind of stupid, maybe it's a just a part of writing code but it seems defining simple functions can really hurt performance severely... I've tried this simple test:</p>
<pre><code>def make_legal_foo_string(x):
return "This is a foo string: " + str(x)
def sum_up_to(x):
return x*(x+1)... | 3 | 2009-09-01T15:09:44Z | 1,363,092 | <p>IMO, this is related to <a href="http://stackoverflow.com/questions/94794/what-is-the-cost-of-a-function-call">Function Call Costs</a>. Which are negligible usually, but not zero. Splitting the code in a lot of very small functions may hurt. Especially in interpreted languages where full optimization is not availabl... | 0 | 2009-09-01T15:26:20Z | [
"python",
"performance"
] |
Encapsulation severely hurts performance? | 1,362,997 | <p>I know this question is kind of stupid, maybe it's a just a part of writing code but it seems defining simple functions can really hurt performance severely... I've tried this simple test:</p>
<pre><code>def make_legal_foo_string(x):
return "This is a foo string: " + str(x)
def sum_up_to(x):
return x*(x+1)... | 3 | 2009-09-01T15:09:44Z | 1,363,108 | <p>There is a performance hit for using functions, since there is the overhead of jumping to a new address, pushing registers on the stack, and returning at the end. This overhead is very small, however, and even in peformance critial systems worrying about such overhead is most likely premature optimization.</p>
<p>... | 0 | 2009-09-01T15:28:42Z | [
"python",
"performance"
] |
Encapsulation severely hurts performance? | 1,362,997 | <p>I know this question is kind of stupid, maybe it's a just a part of writing code but it seems defining simple functions can really hurt performance severely... I've tried this simple test:</p>
<pre><code>def make_legal_foo_string(x):
return "This is a foo string: " + str(x)
def sum_up_to(x):
return x*(x+1)... | 3 | 2009-09-01T15:09:44Z | 1,363,118 | <p>Encapsulation is about one thing and one thing only: Readability. If you're really so worried about performance that you're willing to start stripping out encapsulated logic, you may as well just start coding in assembly.</p>
<p>Encapsulation also assists in debugging and feature adding. Consider the following: let... | 2 | 2009-09-01T15:30:00Z | [
"python",
"performance"
] |
Encapsulation severely hurts performance? | 1,362,997 | <p>I know this question is kind of stupid, maybe it's a just a part of writing code but it seems defining simple functions can really hurt performance severely... I've tried this simple test:</p>
<pre><code>def make_legal_foo_string(x):
return "This is a foo string: " + str(x)
def sum_up_to(x):
return x*(x+1)... | 3 | 2009-09-01T15:09:44Z | 1,363,263 | <p>There is a good technical reason why what you suggested is impossible. In Python, functions, constants, and everything else are <strong>accessible at runtime and can be changed at any time if necessary</strong>; they could also be changed by outside modules. This is an explicit promise of Python and one would need s... | 0 | 2009-09-01T15:53:54Z | [
"python",
"performance"
] |
Pointers and arrays in Python ctypes | 1,363,163 | <p>I have a DLL containing a C function with a prototype like this:</p>
<p><code>int c_read_block(uint32 addr, uint32 *buf, uint32 num);</code></p>
<p>I want to call it from Python using ctypes. The function expects a pointer to a chunk of memory, into which it will write the results. I don't know how to construct an... | 26 | 2009-09-01T15:38:20Z | 1,363,344 | <p>You can cast with the <a href="http://docs.python.org/library/ctypes.html#type-conversions"><code>cast</code></a> function :)</p>
<pre><code>>>> import ctypes
>>> x = (ctypes.c_ulong*5)()
>>> x
<__main__.c_ulong_Array_5 object at 0x00C2DB20>
>>> ctypes.cast(x, ctypes.POINTE... | 43 | 2009-09-01T16:10:10Z | [
"python",
"arrays",
"pointers",
"ctypes"
] |
Pointers and arrays in Python ctypes | 1,363,163 | <p>I have a DLL containing a C function with a prototype like this:</p>
<p><code>int c_read_block(uint32 addr, uint32 *buf, uint32 num);</code></p>
<p>I want to call it from Python using ctypes. The function expects a pointer to a chunk of memory, into which it will write the results. I don't know how to construct an... | 26 | 2009-09-01T15:38:20Z | 36,847,468 | <p>There is a typo in the solution. In order to get a pointer to an array of ulongs you need to cast to a <code>POINTER(list of ulong)</code></p>
<pre><code>In [33]: ptr = ctypes.cast(x, ctypes.POINTER(ctypes.c_ulong*5))
In [34]: ptr
Out[34]: <__main__.LP_c_ulong_Array_5 at 0x23e2560>
</code></pre>
| 0 | 2016-04-25T17:41:09Z | [
"python",
"arrays",
"pointers",
"ctypes"
] |
calling vb dll in python | 1,363,305 | <p>So I have a function in vb that is converted to a dll that I want to use in python. However trying to use it, I get an error message
this is the VB function</p>
<pre><code>Function DISPLAYNAME(Name)
MsgBox ("Hello " & Name & "!")
End Function
</code></pre>
<p>and this is how I call it in python</p>
<pre>... | 3 | 2009-09-01T16:02:39Z | 1,363,322 | <p>I dunno the answer to your specific question, but if it's VB.NET, you can natively call it in <a href="http://www.codeplex.com/IronPython" rel="nofollow">IronPython</a>.</p>
| 0 | 2009-09-01T16:06:37Z | [
"python",
"vb.net",
"dll",
"vb6"
] |
calling vb dll in python | 1,363,305 | <p>So I have a function in vb that is converted to a dll that I want to use in python. However trying to use it, I get an error message
this is the VB function</p>
<pre><code>Function DISPLAYNAME(Name)
MsgBox ("Hello " & Name & "!")
End Function
</code></pre>
<p>and this is how I call it in python</p>
<pre>... | 3 | 2009-09-01T16:02:39Z | 1,363,333 | <p>It might be a scoping issue, with out the Public access modifier, the function may not be visible to external callers. Try</p>
<pre><code>Public Function DISPLAYNAME(Name)
MsgBox ("Hello " & Name & "!")
End Function
</code></pre>
<p>in your dll </p>
| 0 | 2009-09-01T16:08:19Z | [
"python",
"vb.net",
"dll",
"vb6"
] |
Efficient way to use python's lambda, map | 1,363,413 | <p>I need to store a big list of integers in Bigtable(db). For efficiency I am storing them as diff between 2 consecutive items.</p>
<p>for eg:</p>
<pre> original_list = [1005, 1004, 1003, 1004, 1006] </pre>
<p>Storing the above list(which actually contains more than 1000k items) as</p>
<pre>
start = 1005
diff = [-... | 3 | 2009-09-01T16:27:08Z | 1,363,461 | <p>Although I don't get why this should be more efficient, I am pretty sure a for loop will give the best performance:</p>
<pre><code>l = [start]
for i in diff:
l.append(l[-1] + i)
</code></pre>
| 0 | 2009-09-01T16:35:16Z | [
"python",
"performance",
"list",
"lambda",
"map-function"
] |
Efficient way to use python's lambda, map | 1,363,413 | <p>I need to store a big list of integers in Bigtable(db). For efficiency I am storing them as diff between 2 consecutive items.</p>
<p>for eg:</p>
<pre> original_list = [1005, 1004, 1003, 1004, 1006] </pre>
<p>Storing the above list(which actually contains more than 1000k items) as</p>
<pre>
start = 1005
diff = [-... | 3 | 2009-09-01T16:27:08Z | 1,363,463 | <p>The following works for me:</p>
<pre><code>orig = [start]
for x in diff:
orig.append(orig[-1] + x)
</code></pre>
<p>Using <code>map</code> will create an new array of the same size, filled with <code>None</code>. I also find a simple <code>for</code> loop more readable, and in this case as fast as you can get.... | 6 | 2009-09-01T16:35:21Z | [
"python",
"performance",
"list",
"lambda",
"map-function"
] |
Efficient way to use python's lambda, map | 1,363,413 | <p>I need to store a big list of integers in Bigtable(db). For efficiency I am storing them as diff between 2 consecutive items.</p>
<p>for eg:</p>
<pre> original_list = [1005, 1004, 1003, 1004, 1006] </pre>
<p>Storing the above list(which actually contains more than 1000k items) as</p>
<pre>
start = 1005
diff = [-... | 3 | 2009-09-01T16:27:08Z | 1,363,489 | <p>Several of the other respondents have reasonable implementations of the algorithm you asked for, but I'm unclear on exactly what problem it is you're really trying to solve.</p>
<p>Unless the numbers being stored are very large (i.e., overflow an integer and require bignums), your list of diffs won't gain you any e... | 2 | 2009-09-01T16:41:09Z | [
"python",
"performance",
"list",
"lambda",
"map-function"
] |
Efficient way to use python's lambda, map | 1,363,413 | <p>I need to store a big list of integers in Bigtable(db). For efficiency I am storing them as diff between 2 consecutive items.</p>
<p>for eg:</p>
<pre> original_list = [1005, 1004, 1003, 1004, 1006] </pre>
<p>Storing the above list(which actually contains more than 1000k items) as</p>
<pre>
start = 1005
diff = [-... | 3 | 2009-09-01T16:27:08Z | 1,363,491 | <p>For such large data structures numpy will work well. For this example, it's <strong>over 200x faster</strong> (see below), and a bit easier to code, basically just</p>
<pre><code>add.accumulate(diff)
</code></pre>
<p>Comparison between numpy and direct list manipulation:</p>
<pre><code>import numpy as nx
import ... | 7 | 2009-09-01T16:41:17Z | [
"python",
"performance",
"list",
"lambda",
"map-function"
] |
Efficient way to use python's lambda, map | 1,363,413 | <p>I need to store a big list of integers in Bigtable(db). For efficiency I am storing them as diff between 2 consecutive items.</p>
<p>for eg:</p>
<pre> original_list = [1005, 1004, 1003, 1004, 1006] </pre>
<p>Storing the above list(which actually contains more than 1000k items) as</p>
<pre>
start = 1005
diff = [-... | 3 | 2009-09-01T16:27:08Z | 1,363,493 | <p>Perfect for generators:</p>
<pre><code>def diff2abs( diffs, start ):
yield start
for diff in diffs:
start += diff
yield start
start = 1005
diffs = [-1, -1, 1, 2]
original_list = list( diff2abs( diffs, start ))
</code></pre>
| 4 | 2009-09-01T16:41:40Z | [
"python",
"performance",
"list",
"lambda",
"map-function"
] |
Efficient way to use python's lambda, map | 1,363,413 | <p>I need to store a big list of integers in Bigtable(db). For efficiency I am storing them as diff between 2 consecutive items.</p>
<p>for eg:</p>
<pre> original_list = [1005, 1004, 1003, 1004, 1006] </pre>
<p>Storing the above list(which actually contains more than 1000k items) as</p>
<pre>
start = 1005
diff = [-... | 3 | 2009-09-01T16:27:08Z | 1,363,494 | <pre><code>class runningtotal:
def __init__(self, start = 0):
self.total = start
def __call__(self, value):
self.total += value
return self.total
</code></pre>
<p>Now try:</p>
<pre><code>>>> map(runningtotal(start), [0,]+diff)
[1005, 1004, 1003, 1004, 1006]
</code></pre>
| 2 | 2009-09-01T16:41:43Z | [
"python",
"performance",
"list",
"lambda",
"map-function"
] |
Efficient way to use python's lambda, map | 1,363,413 | <p>I need to store a big list of integers in Bigtable(db). For efficiency I am storing them as diff between 2 consecutive items.</p>
<p>for eg:</p>
<pre> original_list = [1005, 1004, 1003, 1004, 1006] </pre>
<p>Storing the above list(which actually contains more than 1000k items) as</p>
<pre>
start = 1005
diff = [-... | 3 | 2009-09-01T16:27:08Z | 1,363,512 | <p>As mshsayem suggested, use list comprehensions - they are generally faster than for loops or map/lambdas (according do Mark Lutz's book Learning Python).</p>
<p>If you really want to use an more FP-ish solution, the proper function would be "scan", wich [I believe] isn't implemented in Python so you would have to i... | 1 | 2009-09-01T16:46:16Z | [
"python",
"performance",
"list",
"lambda",
"map-function"
] |
Efficient way to use python's lambda, map | 1,363,413 | <p>I need to store a big list of integers in Bigtable(db). For efficiency I am storing them as diff between 2 consecutive items.</p>
<p>for eg:</p>
<pre> original_list = [1005, 1004, 1003, 1004, 1006] </pre>
<p>Storing the above list(which actually contains more than 1000k items) as</p>
<pre>
start = 1005
diff = [-... | 3 | 2009-09-01T16:27:08Z | 1,363,614 | <p>I don't know about your reasoning for storing the integers as diffs -- rcoder gave a good answer about why this generally is not more efficient than storing the integers themselves -- but if you don't need to have access to the entire list at once, it's more efficient memory-wise for you to use a generator. Since y... | 0 | 2009-09-01T17:13:30Z | [
"python",
"performance",
"list",
"lambda",
"map-function"
] |
Efficient way to use python's lambda, map | 1,363,413 | <p>I need to store a big list of integers in Bigtable(db). For efficiency I am storing them as diff between 2 consecutive items.</p>
<p>for eg:</p>
<pre> original_list = [1005, 1004, 1003, 1004, 1006] </pre>
<p>Storing the above list(which actually contains more than 1000k items) as</p>
<pre>
start = 1005
diff = [-... | 3 | 2009-09-01T16:27:08Z | 6,575,399 | <p>No comment on the performance of this, but you can use reduce here.</p>
<pre><code>start = 1005
diffs = [-1,-1,1,2]
reduce(lambda undiffed_list, diff: undiffed_list + [undiffed_list[-1] + diff],diffs,[start])
</code></pre>
<p>gets you what you want.</p>
| 0 | 2011-07-04T19:31:30Z | [
"python",
"performance",
"list",
"lambda",
"map-function"
] |
appengine: NeedIndexError: The built-in indices are not efficient enough for this query and your data. Please add a composite index for this query | 1,363,531 | <p>While using django.core.paginator import ObjectPaginator, I'm getting this error:</p>
<blockquote>
<p>NeedIndexError: The built-in indices
are not efficient enough for this
query and your data. Please add a
composite index for this query.</p>
</blockquote>
<p>The original query is written in this form:</p>... | 2 | 2009-09-01T16:50:26Z | 1,363,737 | <p>The general procedure recommended to fix <code>NeedIndexError</code> occurrences is <a href="http://groups.google.com/group/google-appengine/msg/36bf21bab219c376" rel="nofollow">this one</a>. I expect the composite index may not have been built on your development depending on the amount and structure of the data (w... | 2 | 2009-09-01T17:48:34Z | [
"python",
"django",
"google-app-engine",
"gae-datastore"
] |
appengine: NeedIndexError: The built-in indices are not efficient enough for this query and your data. Please add a composite index for this query | 1,363,531 | <p>While using django.core.paginator import ObjectPaginator, I'm getting this error:</p>
<blockquote>
<p>NeedIndexError: The built-in indices
are not efficient enough for this
query and your data. Please add a
composite index for this query.</p>
</blockquote>
<p>The original query is written in this form:</p>... | 2 | 2009-09-01T16:50:26Z | 6,320,352 | <p>I have run into this problem. The problem is not with your code but with GAE's indexing system itself. To fix it, you have to explicitly write the index in your index.yaml file. That worked for me, but I have <a href="http://stackoverflow.com/questions/3025018/appengine-backreferences-need-composite-index">read else... | 1 | 2011-06-12T05:34:19Z | [
"python",
"django",
"google-app-engine",
"gae-datastore"
] |
python DST and GMT management into a scheduler | 1,363,692 | <p>I'm planning to write a sheduler app in python and I wouldn't
be in trouble with DST and GMT handling.</p>
<p>As example see also <a href="http://stackoverflow.com/questions/563053/scheduling-dst">PHP related question 563053</a>.</p>
<p>Does anyone worked already on something similar? </p>
<p>Does anyone already... | 1 | 2009-09-01T17:37:03Z | 1,363,716 | <p>Sure, many of us have worked on calendars / schedulers and are familiar with pytz. What's your specific question, that's not already well answered in the SO question you point to and ITS answers / comments...?</p>
<p><strong>Edit</strong>: so there are no special, particular pitfalls if you do things as recommended... | 3 | 2009-09-01T17:43:26Z | [
"python",
"time",
"calendar",
"timezone",
"utc"
] |
python DST and GMT management into a scheduler | 1,363,692 | <p>I'm planning to write a sheduler app in python and I wouldn't
be in trouble with DST and GMT handling.</p>
<p>As example see also <a href="http://stackoverflow.com/questions/563053/scheduling-dst">PHP related question 563053</a>.</p>
<p>Does anyone worked already on something similar? </p>
<p>Does anyone already... | 1 | 2009-09-01T17:37:03Z | 1,365,798 | <p>pytz works great. Be sure to convert and store your times as UTC and use the pytz/datetime conversion routines to convert to local time. There's an example of usage and timezone conversion <a href="http://parand.com/say/index.php/2008/02/11/parsing-and-normalizing-dates-with-timezones-in-python/" rel="nofollow">here... | 3 | 2009-09-02T04:15:54Z | [
"python",
"time",
"calendar",
"timezone",
"utc"
] |
Python singleton / object instantiation | 1,363,839 | <p>I'm learning Python and i've been trying to implement a Singleton-type class as a test. The code i have is as follows:</p>
<pre><code>_Singleton__instance = None
class Singleton:
def __init__(self):
global __instance
if __instance == None:
self.name = "The one"
... | 5 | 2009-09-01T18:10:16Z | 1,363,852 | <p><strong>From <a href="http://en.wikipedia.org/wiki/Singleton%5Fpattern#Python" rel="nofollow">Singleton Pattern (Python)</a></strong>:</p>
<pre><code>class Singleton(type):
def __init__(self, name, bases, dict):
super(Singleton, self).__init__(name, bases, dict)
self.instance = None
def __c... | 4 | 2009-09-01T18:15:38Z | [
"python",
"singleton"
] |
Python singleton / object instantiation | 1,363,839 | <p>I'm learning Python and i've been trying to implement a Singleton-type class as a test. The code i have is as follows:</p>
<pre><code>_Singleton__instance = None
class Singleton:
def __init__(self):
global __instance
if __instance == None:
self.name = "The one"
... | 5 | 2009-09-01T18:10:16Z | 1,363,856 | <p>This is about the most basic Singleton you can make. It uses a <a href="http://docs.python.org/library/functions.html#classmethod" rel="nofollow">class method</a> to check whether the singleton has been created and makes a new one if it hasn't. There are more advanced ways of going about this, such as overriding t... | 1 | 2009-09-01T18:16:04Z | [
"python",
"singleton"
] |
Python singleton / object instantiation | 1,363,839 | <p>I'm learning Python and i've been trying to implement a Singleton-type class as a test. The code i have is as follows:</p>
<pre><code>_Singleton__instance = None
class Singleton:
def __init__(self):
global __instance
if __instance == None:
self.name = "The one"
... | 5 | 2009-09-01T18:10:16Z | 1,363,857 | <p>Assigning to an argument or any other local variable (barename) cannot ever, possibly have ANY effect outside the function; that applies to your <code>self = whatever</code> as it would to ANY other assignment to a (barename) argument or other local variable.</p>
<p>Rather, override <code>__new__</code>:</p>
<pre>... | 17 | 2009-09-01T18:16:39Z | [
"python",
"singleton"
] |
Python singleton / object instantiation | 1,363,839 | <p>I'm learning Python and i've been trying to implement a Singleton-type class as a test. The code i have is as follows:</p>
<pre><code>_Singleton__instance = None
class Singleton:
def __init__(self):
global __instance
if __instance == None:
self.name = "The one"
... | 5 | 2009-09-01T18:10:16Z | 1,363,858 | <pre><code>self = _instance
</code></pre>
<p>This wont do what you are expecting it to do. Read about how Python treats names.</p>
| 0 | 2009-09-01T18:16:43Z | [
"python",
"singleton"
] |
Python singleton / object instantiation | 1,363,839 | <p>I'm learning Python and i've been trying to implement a Singleton-type class as a test. The code i have is as follows:</p>
<pre><code>_Singleton__instance = None
class Singleton:
def __init__(self):
global __instance
if __instance == None:
self.name = "The one"
... | 5 | 2009-09-01T18:10:16Z | 1,363,867 | <p><a href="http://stackoverflow.com/questions/1296311/bruce-eckels-code-snippet-from-design-pattern-im-confused-on-how-it-works">http://stackoverflow.com/questions/1296311/bruce-eckels-code-snippet-from-design-pattern-im-confused-on-how-it-works</a></p>
<pre><code>class Borg:
_shared_state = {}
def __init__(self)... | 6 | 2009-09-01T18:18:06Z | [
"python",
"singleton"
] |
Invoking a method on an object | 1,364,117 | <p>Given a PyObject* pointing to a python object, how do I invoke one of the object methods? The documentation never gives an example of this:</p>
<pre><code>PyObject* obj = ....
PyObject* args = Py_BuildValue("(s)", "An arg");
PyObject* method = PyWHATGOESHERE(obj, "foo");
PyObject* ret = PyWHATGOESHERE(obj, method, ... | 5 | 2009-09-01T19:08:33Z | 1,364,159 | <pre><code>PyObject* obj = ....
PyObject *ret = PyObject_CallMethod(obj, "foo", "(s)", "An arg");
if (!ret) {
// check error...
}
</code></pre>
<p>Read up on the <a href="http://docs.python.org/c-api/index.html">Python C API documentation</a>. In this case, you want the <a href="http://docs.python.org/c-api/object.... | 6 | 2009-09-01T19:14:33Z | [
"python",
"c",
"embedded-language"
] |
Invoking a method on an object | 1,364,117 | <p>Given a PyObject* pointing to a python object, how do I invoke one of the object methods? The documentation never gives an example of this:</p>
<pre><code>PyObject* obj = ....
PyObject* args = Py_BuildValue("(s)", "An arg");
PyObject* method = PyWHATGOESHERE(obj, "foo");
PyObject* ret = PyWHATGOESHERE(obj, method, ... | 5 | 2009-09-01T19:08:33Z | 1,364,216 | <p>Your example would be:</p>
<pre><code>PyObject* ret = PyObject_CallMethod(obj, "foo", "(s)", "An arg");
</code></pre>
| 2 | 2009-09-01T19:27:05Z | [
"python",
"c",
"embedded-language"
] |
Stopping python using ctrl+c | 1,364,173 | <p>I have a python script that uses threads and makes lots of HTTP requests. I think what's happening is that while a HTTP request (using urllib2) is reading, it's blocking and not responding to <kbd>Ctrl</kbd><kbd>C</kbd> to stop the program. Is there any way around this?</p>
| 45 | 2009-09-01T19:17:13Z | 1,364,179 | <p>If it is running in the Python shell use <kbd>Ctrl</kbd> + <kbd>Z</kbd>, otherwise locate the <code>python</code> process and kill it.</p>
| 23 | 2009-09-01T19:18:43Z | [
"python"
] |
Stopping python using ctrl+c | 1,364,173 | <p>I have a python script that uses threads and makes lots of HTTP requests. I think what's happening is that while a HTTP request (using urllib2) is reading, it's blocking and not responding to <kbd>Ctrl</kbd><kbd>C</kbd> to stop the program. Is there any way around this?</p>
| 45 | 2009-09-01T19:17:13Z | 1,364,199 | <p>The only sure way is to use <kbd>Ctrl</kbd><kbd>Break</kbd>. Stops every python script instantly!</p>
<p>(Note that on some keyboards, "Break" is labeled as "Pause".)</p>
| 58 | 2009-09-01T19:21:49Z | [
"python"
] |
Stopping python using ctrl+c | 1,364,173 | <p>I have a python script that uses threads and makes lots of HTTP requests. I think what's happening is that while a HTTP request (using urllib2) is reading, it's blocking and not responding to <kbd>Ctrl</kbd><kbd>C</kbd> to stop the program. Is there any way around this?</p>
| 45 | 2009-09-01T19:17:13Z | 1,364,409 | <p>Pressing <kbd>Ctrl</kbd> + <kbd>c</kbd> while a python program is running will cause python to raise a <a href="http://docs.python.org/library/exceptions.html#exceptions.KeyboardInterrupt">KeyboardInterupt</a> exception. It's likely that a program that makes lots of HTTP requests will have lots of exception handlin... | 44 | 2009-09-01T20:12:04Z | [
"python"
] |
Stopping python using ctrl+c | 1,364,173 | <p>I have a python script that uses threads and makes lots of HTTP requests. I think what's happening is that while a HTTP request (using urllib2) is reading, it's blocking and not responding to <kbd>Ctrl</kbd><kbd>C</kbd> to stop the program. Is there any way around this?</p>
| 45 | 2009-09-01T19:17:13Z | 21,460,045 | <p>The interrupt process is hardware and OS dependent. So you will have very different behavior depending on where you run your python script. For example, on Windows machines we have <kbd>Ctrl</kbd>+<kbd>C</kbd> (<code>SIGINT</code>) and <kbd>Ctrl</kbd>+<kbd>Break</kbd> (<code>SIGBREAK</code>). </p>
<p>So while SIGIN... | 14 | 2014-01-30T15:05:31Z | [
"python"
] |
Python 3.1 inline division override | 1,364,583 | <p>I don't know if this is a bug in 3.1, but if I remember correctly "inline" division worked like this in pre-3k versions:</p>
<pre><code>Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
... ... | 3 | 2009-09-01T20:50:38Z | 1,364,606 | <p>Gaaah! Found <code>__floordiv__</code> and <code>__truediv__</code>. Sorry!</p>
<p>If you'd like to tell me why 2to3 doesn't translate <code>__idiv__</code> into a <code>__truediv__</code> with a <code>__floordiv__(self, y): self.__truediv__(y)</code>, please go ahead!</p>
| 6 | 2009-09-01T20:54:39Z | [
"python",
"python-3.x"
] |
Python generating Python | 1,364,640 | <p>I have a group of objects which I am creating a class for that I want to store each object as its own text file. I would really like to store it as a Python class definition which subclasses the main class I am creating. So, I did some poking around and found a Python Code Generator on effbot.org. I did some experim... | 8 | 2009-09-01T21:02:28Z | 1,364,714 | <p>This is pretty much the best way to generate Python <em>source</em> code. However, you can also generate Python executable code at runtime using the <a href="http://docs.python.org/3.1/library/ast.html" rel="nofollow"><code>ast</code></a> library. (I linked to the Python 3 version because it's more capable than the ... | 3 | 2009-09-01T21:20:35Z | [
"code-generation",
"python"
] |
Python generating Python | 1,364,640 | <p>I have a group of objects which I am creating a class for that I want to store each object as its own text file. I would really like to store it as a Python class definition which subclasses the main class I am creating. So, I did some poking around and found a Python Code Generator on effbot.org. I did some experim... | 8 | 2009-09-01T21:02:28Z | 1,364,718 | <p>We use Jinja2 to fill in a template. It's much simpler.</p>
<p>The template looks a lot like Python code with a few <code>{{something}}</code> replacements in it.</p>
| 17 | 2009-09-01T21:21:48Z | [
"code-generation",
"python"
] |
Python generating Python | 1,364,640 | <p>I have a group of objects which I am creating a class for that I want to store each object as its own text file. I would really like to store it as a Python class definition which subclasses the main class I am creating. So, I did some poking around and found a Python Code Generator on effbot.org. I did some experim... | 8 | 2009-09-01T21:02:28Z | 1,364,802 | <p>From what I understand you are trying to do, I would consider using reflection to dynamically examine a class at runtime and generate output based on that. There is a good tutorial on reflection (A.K.A. introspection) at <a href="http://diveintopython3.ep.io/" rel="nofollow">http://diveintopython3.ep.io/</a>.</p>
<... | 0 | 2009-09-01T21:46:47Z | [
"code-generation",
"python"
] |
Python generating Python | 1,364,640 | <p>I have a group of objects which I am creating a class for that I want to store each object as its own text file. I would really like to store it as a Python class definition which subclasses the main class I am creating. So, I did some poking around and found a Python Code Generator on effbot.org. I did some experim... | 8 | 2009-09-01T21:02:28Z | 1,365,122 | <p>I'm not sure whether this is especially Pythonic, but you could use operator overloading:</p>
<pre><code>class CodeGenerator:
def __init__(self, indentation='\t'):
self.indentation = indentation
self.level = 0
self.code = ''
def indent(self):
self.level += 1
def dedent(... | 0 | 2009-09-01T23:15:49Z | [
"code-generation",
"python"
] |
Python generating Python | 1,364,640 | <p>I have a group of objects which I am creating a class for that I want to store each object as its own text file. I would really like to store it as a Python class definition which subclasses the main class I am creating. So, I did some poking around and found a Python Code Generator on effbot.org. I did some experim... | 8 | 2009-09-01T21:02:28Z | 1,365,182 | <p>Just read your comment to wintermute - ie:</p>
<blockquote>
<p>What I have is a bunch of planets that
I want to store each as their own text
files. I'm not particularly attached
to storing them as python source code,
but I am attached to making them
human-readable.</p>
</blockquote>
<p>If that's the ca... | 7 | 2009-09-01T23:39:09Z | [
"code-generation",
"python"
] |
Python generating Python | 1,364,640 | <p>I have a group of objects which I am creating a class for that I want to store each object as its own text file. I would really like to store it as a Python class definition which subclasses the main class I am creating. So, I did some poking around and found a Python Code Generator on effbot.org. I did some experim... | 8 | 2009-09-01T21:02:28Z | 28,443,506 | <p>I'd recommend using <a href="https://github.com/audreyr/cookiecutter" rel="nofollow">cookiecutter</a> for generating code.</p>
| 3 | 2015-02-10T22:58:04Z | [
"code-generation",
"python"
] |
Block requests from *.appspot.com and force custom domain in Google App Engine | 1,364,733 | <p>How can I prevent a user from accessing my app at example.appspot.com and force them to access it at example.com? I already have example.com working, but I don't want users to be able to access the appspot domain. I'm using python.</p>
| 14 | 2009-09-01T21:26:11Z | 1,364,875 | <p>You can check if <code>os.environ['HTTP_HOST'].endswith('.appspot.com')</code> -- if so, then you're serving from <code>something.appspot.com</code> and can send a redirect, or otherwise alter your behavior as desired.</p>
<p>You could deploy this check-and-redirect-if-needed (or other behavior alteration of your c... | 15 | 2009-09-01T22:02:16Z | [
"python",
"google-app-engine",
"redirect"
] |
Block requests from *.appspot.com and force custom domain in Google App Engine | 1,364,733 | <p>How can I prevent a user from accessing my app at example.appspot.com and force them to access it at example.com? I already have example.com working, but I don't want users to be able to access the appspot domain. I'm using python.</p>
| 14 | 2009-09-01T21:26:11Z | 1,404,772 | <pre><code>def redirect_from_appspot(wsgi_app):
def redirect_if_needed(env, start_response):
if env["HTTP_HOST"].startswith('my_app_name.appspot.com'):
import webob, urlparse
request = webob.Request(env)
scheme, netloc, path, query, fragment = urlparse.urlsplit(request.url)
url = url... | 3 | 2009-09-10T11:36:06Z | [
"python",
"google-app-engine",
"redirect"
] |
Block requests from *.appspot.com and force custom domain in Google App Engine | 1,364,733 | <p>How can I prevent a user from accessing my app at example.appspot.com and force them to access it at example.com? I already have example.com working, but I don't want users to be able to access the appspot domain. I'm using python.</p>
| 14 | 2009-09-01T21:26:11Z | 1,980,033 | <p>The code posted above has two problems - it tries to redirect secure traffic (which isn't supported on custom domains), and also your cron jobs will fail when Google call them on your appspot domain and you serve up a 301.</p>
<p>I posted a slightly modified version to my blog:
<a href="http://blog.dantup.com/2009/... | 7 | 2009-12-30T12:45:25Z | [
"python",
"google-app-engine",
"redirect"
] |
Block requests from *.appspot.com and force custom domain in Google App Engine | 1,364,733 | <p>How can I prevent a user from accessing my app at example.appspot.com and force them to access it at example.com? I already have example.com working, but I don't want users to be able to access the appspot domain. I'm using python.</p>
| 14 | 2009-09-01T21:26:11Z | 23,743,686 | <p>In case you are using <a href="https://webapp-improved.appspot.com/" rel="nofollow">webapp2</a>, a slightly easier (depending on your use case) solution is possible using its <code>DomainRoute</code>.</p>
<p>If this is your URL map:</p>
<pre><code>url_map = [
('/', HomeHandler),
('/about', AboutHandler),
... | 0 | 2014-05-19T17:25:03Z | [
"python",
"google-app-engine",
"redirect"
] |
Block requests from *.appspot.com and force custom domain in Google App Engine | 1,364,733 | <p>How can I prevent a user from accessing my app at example.appspot.com and force them to access it at example.com? I already have example.com working, but I don't want users to be able to access the appspot domain. I'm using python.</p>
| 14 | 2009-09-01T21:26:11Z | 24,758,934 | <p>You can redirect it to your custom domain (here <code>example.com</code>) by overriding the <code>initialize</code> method in your <code>webapp2.RequestHandler</code> base class the following way :</p>
<pre><code>def initialize(self, *a, **kw):
webapp2.RequestHandler.initialize(self, *a, **kw)
if self.requ... | 1 | 2014-07-15T13:03:06Z | [
"python",
"google-app-engine",
"redirect"
] |
How to connect to a GObject signal in python, without it keeping a reference to the connecter? | 1,364,923 | <p>The problem is basically this, in python's gobject and gtk bindings. Assume we have a class that binds to a signal when constructed:</p>
<pre><code>class ClipboardMonitor (object):
def __init__(self):
clip = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD)
clip.connect("owner-change", self._clipboard_change... | 2 | 2009-09-01T22:16:52Z | 1,364,959 | <p>The standard way is to disconnect the signal. This however needs to have a destructor-like method in your class, called explicitly by code which maintains your object. This is necessary, because otherwise you'll get circular dependency.</p>
<pre><code>class ClipboardMonitor(object):
[...]
def __init__(self... | 6 | 2009-09-01T22:27:56Z | [
"python",
"pygtk",
"pygobject"
] |
How to connect to a GObject signal in python, without it keeping a reference to the connecter? | 1,364,923 | <p>The problem is basically this, in python's gobject and gtk bindings. Assume we have a class that binds to a signal when constructed:</p>
<pre><code>class ClipboardMonitor (object):
def __init__(self):
clip = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD)
clip.connect("owner-change", self._clipboard_change... | 2 | 2009-09-01T22:16:52Z | 1,365,131 | <p>(This answer tracks my progress)</p>
<p>This second version will disconnect as well; I have a convenience function for gobjects, but I actually need this class for a more general case -- both for D-Bus signal callbacks and GObject callbacks.</p>
<p>Anyway, what can one call the <code>WeakCallback</code> implementa... | 0 | 2009-09-01T23:20:06Z | [
"python",
"pygtk",
"pygobject"
] |
How to connect to a GObject signal in python, without it keeping a reference to the connecter? | 1,364,923 | <p>The problem is basically this, in python's gobject and gtk bindings. Assume we have a class that binds to a signal when constructed:</p>
<pre><code>class ClipboardMonitor (object):
def __init__(self):
clip = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD)
clip.connect("owner-change", self._clipboard_change... | 2 | 2009-09-01T22:16:52Z | 1,726,152 | <p>not actually tried it yet, but:</p>
<pre><code>class WeakCallback(object):
"""
Used to wrap bound methods without keeping a ref to the underlying object.
You can also pass in user_data and user_kwargs in the same way as with
rpartial. Note that refs will be kept to everything you pass in other than
... | 0 | 2009-11-12T23:30:29Z | [
"python",
"pygtk",
"pygobject"
] |
Python on Snow Leopard, how to open >255 sockets? | 1,364,955 | <p>Consider this code:</p>
<pre><code>import socket
store = []
scount = 0
while True:
scount+=1
print "Creating socket %d" % (scount)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
store.append(s)
</code></pre>
<p>Gives the following result:</p>
<pre><code>Creating socket 1
Creating socket 2
.... | 4 | 2009-09-01T22:27:06Z | 1,364,989 | <p>Did you install XCode and the developer tools off the Snow Leopard install disk? I'm able to open way more ports than you're able to:</p>
<pre><code>Creating socket 1
Creating socket 2
...
Creating socket 7161
Creating socket 7162
Creating socket 7163
Creating socket 7164
Creating socket 7165
Creating socket 7166
T... | 1 | 2009-09-01T22:36:14Z | [
"python",
"sockets",
"osx"
] |
Python on Snow Leopard, how to open >255 sockets? | 1,364,955 | <p>Consider this code:</p>
<pre><code>import socket
store = []
scount = 0
while True:
scount+=1
print "Creating socket %d" % (scount)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
store.append(s)
</code></pre>
<p>Gives the following result:</p>
<pre><code>Creating socket 1
Creating socket 2
.... | 4 | 2009-09-01T22:27:06Z | 1,365,014 | <p>You can increase available sockets with <code>ulimit</code>. Looks like 1200 is the max for non-root users in bash. I can get up to 10240 with zsh.</p>
<pre><code>$ ulimit -n 1200
$ python sockets
....
Creating socket 1197
Creating socket 1198
Traceback (most recent call last):
File "sockets", line 7, in <modu... | 16 | 2009-09-01T22:44:06Z | [
"python",
"sockets",
"osx"
] |
Python packages depending on libxml2 and libxslt | 1,365,075 | <p>Apart from <code>lxml</code>, is anyone aware of Python packages that depend on libxml2 and libxslt?</p>
| 0 | 2009-09-01T23:01:34Z | 1,365,180 | <p>See e.g. the list <a href="http://www.xmlsoft.org/XSLT/python.html" rel="nofollow">here</a> -- not exhaustive, as the page itself says, but a start.</p>
| 1 | 2009-09-01T23:38:41Z | [
"python",
"dependencies",
"lxml",
"libxml2",
"libxslt"
] |
virtualenv in PowerShell? | 1,365,081 | <p>Hi fellow pythonistas, there seems to be a problem when <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a> is used in PowerShell.</p>
<p>When I try to activate my environment in PowerShell like..</p>
<p>> env/scripts/activate</p>
<p>.. nothing happens. (the shell prompt should have changed as well... | 11 | 2009-09-01T23:03:59Z | 1,365,119 | <p><a href="http://www.leeholmes.com/blog/NothingSolvesEverythingPowerShellAndOtherTechnologies.aspx">Here</a>'s a post which contains a Powershell script which allows you to run batch files that persistently modify their environment variables. The script propagates any environment variable changes back to the calling ... | 8 | 2009-09-01T23:15:02Z | [
"python",
"powershell",
"virtualenv"
] |
virtualenv in PowerShell? | 1,365,081 | <p>Hi fellow pythonistas, there seems to be a problem when <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a> is used in PowerShell.</p>
<p>When I try to activate my environment in PowerShell like..</p>
<p>> env/scripts/activate</p>
<p>.. nothing happens. (the shell prompt should have changed as well... | 11 | 2009-09-01T23:03:59Z | 3,927,458 | <p>A quick work-around would be to invoke cmd and then run your activate.bat from within the cmd session. For example:</p>
<pre><code>PS C:\my_cool_env\Scripts> cmd
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\my_cool_env\Scripts>activate.bat
(my_cool_... | 2 | 2010-10-13T19:52:47Z | [
"python",
"powershell",
"virtualenv"
] |
virtualenv in PowerShell? | 1,365,081 | <p>Hi fellow pythonistas, there seems to be a problem when <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a> is used in PowerShell.</p>
<p>When I try to activate my environment in PowerShell like..</p>
<p>> env/scripts/activate</p>
<p>.. nothing happens. (the shell prompt should have changed as well... | 11 | 2009-09-01T23:03:59Z | 10,030,999 | <p><strong><a href="http://pypi.python.org/pypi/virtualenv">The latest version of virtualenv</a> supports PowerShell out-of-the-box</strong>.</p>
<p>Just make sure you run:</p>
<pre><code>Scripts\activate.ps1
</code></pre>
<p>instead of</p>
<pre><code>Scripts\activate
</code></pre>
<p>The latter will execute <code... | 26 | 2012-04-05T14:56:40Z | [
"python",
"powershell",
"virtualenv"
] |
virtualenv in PowerShell? | 1,365,081 | <p>Hi fellow pythonistas, there seems to be a problem when <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a> is used in PowerShell.</p>
<p>When I try to activate my environment in PowerShell like..</p>
<p>> env/scripts/activate</p>
<p>.. nothing happens. (the shell prompt should have changed as well... | 11 | 2009-09-01T23:03:59Z | 29,918,484 | <p>try this:
<code>. .\env\Scripts\activate.ps1</code>
watch dots and spaces</p>
| -1 | 2015-04-28T11:41:41Z | [
"python",
"powershell",
"virtualenv"
] |
virtualenv in PowerShell? | 1,365,081 | <p>Hi fellow pythonistas, there seems to be a problem when <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a> is used in PowerShell.</p>
<p>When I try to activate my environment in PowerShell like..</p>
<p>> env/scripts/activate</p>
<p>.. nothing happens. (the shell prompt should have changed as well... | 11 | 2009-09-01T23:03:59Z | 34,651,375 | <p>This error happens due to a security measure which won't let scripts be executed on your system without you having approved of it. You can do so by opening up a powershell with administrative rights (search for powershell in the main menu and select Run as administrator from the context menu) and entering:</p>
<p><... | 1 | 2016-01-07T09:21:17Z | [
"python",
"powershell",
"virtualenv"
] |
Is storing user configuration settings on database OK? | 1,365,164 | <p>I'm building a fairly large enterprise application made in python that on its first version will require network connection.</p>
<p>I've been thinking in keeping some user settings stored on the database, instead of a file in the users home folder.</p>
<p>Some of the advantages I've thought of are:</p>
<ul>
<li>t... | 2 | 2009-09-01T23:32:52Z | 1,365,175 | <p>One caveat might depend on where the user is using the application from. For example, if they use two computers with different screen resolutions, and 'selected zoom/text size' is one of the things you associate with the user, it might not always be suitable. It depends what kind of settings you intend to allow the ... | 5 | 2009-09-01T23:36:38Z | [
"python",
"database",
"settings",
"code-smell"
] |
Is storing user configuration settings on database OK? | 1,365,164 | <p>I'm building a fairly large enterprise application made in python that on its first version will require network connection.</p>
<p>I've been thinking in keeping some user settings stored on the database, instead of a file in the users home folder.</p>
<p>Some of the advantages I've thought of are:</p>
<ul>
<li>t... | 2 | 2009-09-01T23:32:52Z | 1,365,176 | <p>Do you need the database to run any part of the application? If that's the case there are no reasons <strong>not</strong> to store the config inside the DB. You already mentioned the benefits and there are no downsides.</p>
| 3 | 2009-09-01T23:36:46Z | [
"python",
"database",
"settings",
"code-smell"
] |
Is storing user configuration settings on database OK? | 1,365,164 | <p>I'm building a fairly large enterprise application made in python that on its first version will require network connection.</p>
<p>I've been thinking in keeping some user settings stored on the database, instead of a file in the users home folder.</p>
<p>Some of the advantages I've thought of are:</p>
<ul>
<li>t... | 2 | 2009-09-01T23:32:52Z | 1,365,178 | <p>This is pretty standard. Go for it.</p>
<p>The caveat is that when you take the database down for maintenance, no one can use the app because their profile is inaccessible. You can either solve that by making a 100%-on db solution, or, more easily, through some form of caching of profiles locally (an "offline" mode... | 8 | 2009-09-01T23:38:23Z | [
"python",
"database",
"settings",
"code-smell"
] |
Is storing user configuration settings on database OK? | 1,365,164 | <p>I'm building a fairly large enterprise application made in python that on its first version will require network connection.</p>
<p>I've been thinking in keeping some user settings stored on the database, instead of a file in the users home folder.</p>
<p>Some of the advantages I've thought of are:</p>
<ul>
<li>t... | 2 | 2009-09-01T23:32:52Z | 1,365,183 | <p>It's perfectly reasonable to keep user settings in the database, as long as the settings pertain to the application independent of user location. One possible advantage of a file in the user's home folder is that users can send settings to one another. You may of course regard this as an advantage or a disadvantage ... | 3 | 2009-09-01T23:39:42Z | [
"python",
"database",
"settings",
"code-smell"
] |
How to deal with user authentication and wrongful modification in scripting languages? | 1,365,254 | <p>I'm building a centralized desktop application using Python/wxPython. One of the requirements is User authentication, which I'm trying to implement using LDAP (although this is not mandatory).</p>
<p>Users of the system will be mechanical and electrical engineers making budgets, and the biggest problem would be ind... | 2 | 2009-09-02T00:03:32Z | 1,365,394 | <p>Possibly:</p>
<ol>
<li>The user enters their credentials into the desktop client.</li>
<li>The client says to the server: "Hi, my name username and my password is password".</li>
<li>The server checks these.</li>
<li>The server says to the client: "Hi, username. Here is your secret token: ..."</li>
<li>Subsequentl... | 1 | 2009-09-02T00:53:33Z | [
"python",
"security",
"design-patterns",
"authentication",
"cracking"
] |
How to deal with user authentication and wrongful modification in scripting languages? | 1,365,254 | <p>I'm building a centralized desktop application using Python/wxPython. One of the requirements is User authentication, which I'm trying to implement using LDAP (although this is not mandatory).</p>
<p>Users of the system will be mechanical and electrical engineers making budgets, and the biggest problem would be ind... | 2 | 2009-09-02T00:03:32Z | 1,365,422 | <p>How malicious are your users? Really.</p>
<p>Exactly how malicious?</p>
<p>If your users are evil sociopaths and can't be trusted with a desktop solution, then <strong>don't build a desktop solution</strong>. Build a web site.</p>
<p>If your users are ordinary users, they'll screw the environment up by installi... | 3 | 2009-09-02T01:07:36Z | [
"python",
"security",
"design-patterns",
"authentication",
"cracking"
] |
On localhost, how to pick a free port number? | 1,365,265 | <p>I try to play with inter process communication and since I could not figure out how to use named pipes under Windows I thought I'll use network sockets. Everything happens locally, server is able to launch slaves in a separate process and listens on some port and the slaves do their work and submit the result to the... | 91 | 2009-09-02T00:07:14Z | 1,365,281 | <p>Bind the socket to port 0. A random free port from 1024 to 65535 will be selected. You may retrieve the selected port with <code>getsockname()</code> right after <code>bind()</code>.</p>
| 28 | 2009-09-02T00:12:53Z | [
"python",
"sockets",
"ipc",
"port"
] |
On localhost, how to pick a free port number? | 1,365,265 | <p>I try to play with inter process communication and since I could not figure out how to use named pipes under Windows I thought I'll use network sockets. Everything happens locally, server is able to launch slaves in a separate process and listens on some port and the slaves do their work and submit the result to the... | 91 | 2009-09-02T00:07:14Z | 1,365,283 | <p>You can listen on whatever port you want; generally, user applications should listen to ports 1024 and above (through 65535). The main thing if you have a variable number of listeners is to allocate a range to your app - say 20000-21000, and <em>CATCH EXCEPTIONS</em>. That is how you will know if a port is unusabl... | 2 | 2009-09-02T00:13:25Z | [
"python",
"sockets",
"ipc",
"port"
] |
On localhost, how to pick a free port number? | 1,365,265 | <p>I try to play with inter process communication and since I could not figure out how to use named pipes under Windows I thought I'll use network sockets. Everything happens locally, server is able to launch slaves in a separate process and listens on some port and the slaves do their work and submit the result to the... | 91 | 2009-09-02T00:07:14Z | 1,365,284 | <p>Do not bind to a specific port, or bind to port 0, e.g. <code>sock.bind(('', 0))</code>. The OS will then pick an available port for you. You can get the port that was chosen using <code>sock.getsockname()[1]</code>, and pass it on to the slaves so that they can connect back.</p>
| 143 | 2009-09-02T00:14:14Z | [
"python",
"sockets",
"ipc",
"port"
] |
What's a server equivalent of django.test.client to test external URL fetch? | 1,365,279 | <p>I'd like to make sure a given view in my test is fetching an external URL properly. It uses urllib2 (but this shouldn't matter, since it's blackbox testing). Perhaps a temporary local server of some kind? Is there an app that does this already? (My Googling has failed me.)</p>
| 0 | 2009-09-02T00:12:35Z | 1,365,296 | <p>Your module under test presumably imports urllib2. You can monkey-patch the module in your test harness to point to your own fake urllib2 - for instance, this needn't be a module, it could be a class instance which has an urlopen method which checks that the correct url is called and returns a suitable response.</p>... | 3 | 2009-09-02T00:19:06Z | [
"python",
"django",
"testing"
] |
What's a server equivalent of django.test.client to test external URL fetch? | 1,365,279 | <p>I'd like to make sure a given view in my test is fetching an external URL properly. It uses urllib2 (but this shouldn't matter, since it's blackbox testing). Perhaps a temporary local server of some kind? Is there an app that does this already? (My Googling has failed me.)</p>
| 0 | 2009-09-02T00:12:35Z | 1,365,434 | <p>You can use <a href="http://docs.python.org/library/simplehttpserver.html" rel="nofollow">SimpleHTTPServer</a> to rig up a fake web server for testing.</p>
<p>We use the WSGI reference implementation, <a href="http://docs.python.org/library/wsgiref.html" rel="nofollow">wsgiref</a>, to rig up a fake web server for t... | 2 | 2009-09-02T01:12:34Z | [
"python",
"django",
"testing"
] |
What's a server equivalent of django.test.client to test external URL fetch? | 1,365,279 | <p>I'd like to make sure a given view in my test is fetching an external URL properly. It uses urllib2 (but this shouldn't matter, since it's blackbox testing). Perhaps a temporary local server of some kind? Is there an app that does this already? (My Googling has failed me.)</p>
| 0 | 2009-09-02T00:12:35Z | 36,316,530 | <p>I'm a huge fan of <a href="https://github.com/kevin1024/vcrpy" rel="nofollow">vcrpy</a> (<a href="https://pypi.python.org/pypi/vcrpy" rel="nofollow">PyPI</a>) when testing external URLs. It can record HTTP interactions to a file and play them back when the test is run later. The easiest way to use it is a decorator ... | 0 | 2016-03-30T18:12:23Z | [
"python",
"django",
"testing"
] |
Center Google Map Based on geocoded IP | 1,365,722 | <p>Basically whenever someones opens up my (Google) map I want it default to their approximate location.</p>
<p>Is there an easy way to do it with Google's API or do I have to write a custom code (this is python based app)?</p>
| 5 | 2009-09-02T03:38:31Z | 1,365,734 | <p>Check out <a href="http://www.ipinfodb.com/" rel="nofollow">http://www.ipinfodb.com/</a>. You can get a latitude and longitude value by passing their services an IP address. I did something recently where I created a simple service that grabbed the current IP address and then passed it to the service ("api/location/... | 3 | 2009-09-02T03:44:27Z | [
"javascript",
"python",
"django",
"google-maps"
] |
Center Google Map Based on geocoded IP | 1,365,722 | <p>Basically whenever someones opens up my (Google) map I want it default to their approximate location.</p>
<p>Is there an easy way to do it with Google's API or do I have to write a custom code (this is python based app)?</p>
| 5 | 2009-09-02T03:38:31Z | 1,365,739 | <p>Per <a href="http://code.google.com/apis/maps/documentation/introduction.html#Initializing%5Fthe%5FMap" rel="nofollow">the docs</a>, just <code>map.setCenter(new GLatLng(37.4419, -122.1419), 13);</code> or whatever other coordinates. Doing it in the page's Javascript is normally preferred.</p>
<p>If you mean trans... | 0 | 2009-09-02T03:46:37Z | [
"javascript",
"python",
"django",
"google-maps"
] |
Center Google Map Based on geocoded IP | 1,365,722 | <p>Basically whenever someones opens up my (Google) map I want it default to their approximate location.</p>
<p>Is there an easy way to do it with Google's API or do I have to write a custom code (this is python based app)?</p>
| 5 | 2009-09-02T03:38:31Z | 1,365,757 | <p>If the user uses FireFox 3.5/google gears, you can retrieve the lat and lng from the browser itself.
You'll find details on another <a href="http://stackoverflow.com/questions/1177726/where-is-a-sample-of-some-javascript-code-for-location-aware-browsing-in-firefox">stackoverflow post here</a></p>
| 0 | 2009-09-02T03:54:22Z | [
"javascript",
"python",
"django",
"google-maps"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.