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 |
|---|---|---|---|---|---|---|---|---|---|
_lsprof.c profiler behaviour towards python multi-threading | 443,082 | <p>This is a question about Python native c file _lsprof.
How does _lsprof.profile() profiler counts total time spent on a function f in a multi-threaded program if the execution of f is interrupted by another thread? </p>
<p>For example:</p>
<p>def f():<br />
linef1<br />
linef2<br />
linef3 </p>
<p>def g()... | 1 | 2009-01-14T14:17:20Z | 579,883 | <p>Quoting from the <a href="http://docs.python.org/library/sys.html#sys.setprofile" rel="nofollow">documentation for setprofile</a>:</p>
<blockquote>
<p>The function is thread-specific, but
there is no way for the profiler to
know about context switches between
threads, so it does not make sense to
use this... | 1 | 2009-02-23T23:44:13Z | [
"python",
"multithreading"
] |
_lsprof.c profiler behaviour towards python multi-threading | 443,082 | <p>This is a question about Python native c file _lsprof.
How does _lsprof.profile() profiler counts total time spent on a function f in a multi-threaded program if the execution of f is interrupted by another thread? </p>
<p>For example:</p>
<p>def f():<br />
linef1<br />
linef2<br />
linef3 </p>
<p>def g()... | 1 | 2009-01-14T14:17:20Z | 661,707 | <p>Thank you for this answer! Actually I am running one profiler in each context, so the question make sense. From the tests I made the profiler would measure "linef1 linef2 linef3" in the above example.</p>
| 0 | 2009-03-19T10:38:35Z | [
"python",
"multithreading"
] |
Jython, Query multiple columns dynamically | 443,224 | <p>I am working with a oracle database and Jython.</p>
<p>I can get data pulled from the database no problem.</p>
<pre><code>results = statement.executeQuery("select %s from %s where column_id = '%s'", % (column, table, id))
</code></pre>
<p>This works fine if I want to pull one column of data.</p>
<p>Say I wanted ... | 1 | 2009-01-14T14:49:41Z | 443,331 | <p>You could simply substitute all the columns into your query as a single string, like this:</p>
<pre><code>columns = ['column1', 'column2', 'column3', 'column4', 'column5']
results = statement.executeQuery("select %s from %s where column_id = '%s'" % (",".join(columns), table, id))
</code></pre>
<p>By the way, this... | 3 | 2009-01-14T15:19:30Z | [
"python",
"oracle10g",
"jython"
] |
Why does Paramiko hang if you use it while loading a module? | 443,387 | <p>Put the following into a file <strong>hello.py</strong> (and <code>easy_install paramiko</code> if you haven't got it):</p>
<pre><code>hostname,username,password='fill','these','in'
import paramiko
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(hostname=hostname, username... | 8 | 2009-01-14T15:35:25Z | 450,895 | <p>Paramiko uses separate threads for the underlying transport.
You should <em>never</em> have a module that spawns a thread as a side effect of importing. As I understand it, there is a single import lock available, so when a child thread from your module attempts another import, it can block indefinitely, because you... | 13 | 2009-01-16T16:01:36Z | [
"python",
"multithreading",
"ssh",
"module",
"paramiko"
] |
Why does Paramiko hang if you use it while loading a module? | 443,387 | <p>Put the following into a file <strong>hello.py</strong> (and <code>easy_install paramiko</code> if you haven't got it):</p>
<pre><code>hostname,username,password='fill','these','in'
import paramiko
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(hostname=hostname, username... | 8 | 2009-01-14T15:35:25Z | 32,875,571 | <p>As <a href="https://stackoverflow.com/a/450895/1729555">JimB</a> pointed out it is an <strong>import issue</strong> when python tries to implicitly import the <code>str.decode('utf-8')</code> decoder on first use during an ssh connection attempt. See <em>Analysis</em> section for details.</p>
<p>In general, one can... | 2 | 2015-09-30T21:02:11Z | [
"python",
"multithreading",
"ssh",
"module",
"paramiko"
] |
Why does Paramiko hang if you use it while loading a module? | 443,387 | <p>Put the following into a file <strong>hello.py</strong> (and <code>easy_install paramiko</code> if you haven't got it):</p>
<pre><code>hostname,username,password='fill','these','in'
import paramiko
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(hostname=hostname, username... | 8 | 2009-01-14T15:35:25Z | 36,416,687 | <p>"".decode("utf-8") didn't work for me, I ended up doing this.</p>
<pre><code>from paramiko import py3compat
# dirty hack to fix threading import lock (issue 104) by preloading module
py3compat.u("dirty hack")
</code></pre>
<p>I have a wrapper for paramiko with that implemented.
<a href="https://github.com/bucknern... | 0 | 2016-04-05T03:36:47Z | [
"python",
"multithreading",
"ssh",
"module",
"paramiko"
] |
Django template ifequal comparison of decimals | 443,650 | <p>So, I have a decimalfield that can be 3 different values. In my view,
I pass in a dictionary of values that contains the appropriate decimal
values as keys.</p>
<pre><code>{% for item in booklist %}
{% for key, value in numvec.items %}
{{item.number}}
{% ifequals item.number {{key}} %}
... | 1 | 2009-01-14T16:27:22Z | 444,142 | <p>According to <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#ifequal" rel="nofollow">this</a>, it seems you can only compare strings. I'd make my own <a href="http://www.mechanicalgirl.com/view/custom-template-tags-in-django/" rel="nofollow">template tag</a> if I were you. </p>
| 2 | 2009-01-14T18:30:24Z | [
"python",
"django",
"django-templates"
] |
Django template ifequal comparison of decimals | 443,650 | <p>So, I have a decimalfield that can be 3 different values. In my view,
I pass in a dictionary of values that contains the appropriate decimal
values as keys.</p>
<pre><code>{% for item in booklist %}
{% for key, value in numvec.items %}
{{item.number}}
{% ifequals item.number {{key}} %}
... | 1 | 2009-01-14T16:27:22Z | 448,121 | <p>Simplest solution is to define a method on the model which encapsulates the numeric logic and returns the human-friendly string.</p>
<p>Or you can write a template tag to do it, which is a lot more code, but perhaps preserves the model/view layer separation a bit better.</p>
| 0 | 2009-01-15T19:30:01Z | [
"python",
"django",
"django-templates"
] |
Django template ifequal comparison of decimals | 443,650 | <p>So, I have a decimalfield that can be 3 different values. In my view,
I pass in a dictionary of values that contains the appropriate decimal
values as keys.</p>
<pre><code>{% for item in booklist %}
{% for key, value in numvec.items %}
{{item.number}}
{% ifequals item.number {{key}} %}
... | 1 | 2009-01-14T16:27:22Z | 999,518 | <p>It's not quite clear if this would help Ardesco but there is <a href="http://code.google.com/p/django-template-utils/" rel="nofollow">template_utils</a> which has <code>if_greater</code>, <code>if_greater_or_equal</code>, <code>if_less</code>, <code>if_less_or_equal</code> tags (among others) which solve very relate... | 0 | 2009-06-16T04:05:00Z | [
"python",
"django",
"django-templates"
] |
Django template ifequal comparison of decimals | 443,650 | <p>So, I have a decimalfield that can be 3 different values. In my view,
I pass in a dictionary of values that contains the appropriate decimal
values as keys.</p>
<pre><code>{% for item in booklist %}
{% for key, value in numvec.items %}
{{item.number}}
{% ifequals item.number {{key}} %}
... | 1 | 2009-01-14T16:27:22Z | 2,644,432 | <p>It is not a bug and <strong>it is possible</strong> to achieve what you're trying to do. </p>
<p>However, first of all few remarks about your code:</p>
<ul>
<li>There is no "ifequals/endifequals" operator. You either use <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#ifequal">"ifequal/endife... | 11 | 2010-04-15T10:25:19Z | [
"python",
"django",
"django-templates"
] |
Django template ifequal comparison of decimals | 443,650 | <p>So, I have a decimalfield that can be 3 different values. In my view,
I pass in a dictionary of values that contains the appropriate decimal
values as keys.</p>
<pre><code>{% for item in booklist %}
{% for key, value in numvec.items %}
{{item.number}}
{% ifequals item.number {{key}} %}
... | 1 | 2009-01-14T16:27:22Z | 3,360,593 | <p>The solution:</p>
<pre><code>{% for item in decimals %}
{% if item|stringformat:"s" == variable %}
{{ variable }}
{% endif %}
{% endfor %}
</code></pre>
<p>works well for comparing a decimal (like the loop) to a string (like a passed value)</p>
| 2 | 2010-07-29T08:21:57Z | [
"python",
"django",
"django-templates"
] |
Django template ifequal comparison of decimals | 443,650 | <p>So, I have a decimalfield that can be 3 different values. In my view,
I pass in a dictionary of values that contains the appropriate decimal
values as keys.</p>
<pre><code>{% for item in booklist %}
{% for key, value in numvec.items %}
{{item.number}}
{% ifequals item.number {{key}} %}
... | 1 | 2009-01-14T16:27:22Z | 26,768,872 | <p>In contrast, numbers like 1.1 and 2.2 do not have exact representations in binary floating point. <a href="https://docs.python.org/2/library/decimal.html" rel="nofollow"> >> </a> </p>
<p>E.g. if you </p>
<pre><code>print Decimal(3.59)
</code></pre>
<p>you get </p>
<pre><code>3.58999999999999985789145284797996282... | 0 | 2014-11-05T23:05:36Z | [
"python",
"django",
"django-templates"
] |
Addressing instance name string in __init__(self) in Python | 443,775 | <p>I am doing something like this:</p>
<pre><code>class Class(object):
def __init__(self):
self.var=#new instance name string#
</code></pre>
<p>How do I make the __ init __ method of my instance to use the instance name string for 'c'? Say in case:</p>
<pre><code>c=Class()
</code></pre>
<p>I want c.v... | 4 | 2009-01-14T16:55:48Z | 443,833 | <p>That isn't possible. You seem to be confusing variables and objects.</p>
<p>In any case there may well not be a variable:</p>
<p>e.g.</p>
<pre><code>foo(Class())
Class().arbitraryMethod()
</code></pre>
<p>Or multiple:</p>
<pre><code>a = b = Class()
</code></pre>
| 0 | 2009-01-14T17:04:52Z | [
"python",
"instance",
"instantiation"
] |
Addressing instance name string in __init__(self) in Python | 443,775 | <p>I am doing something like this:</p>
<pre><code>class Class(object):
def __init__(self):
self.var=#new instance name string#
</code></pre>
<p>How do I make the __ init __ method of my instance to use the instance name string for 'c'? Say in case:</p>
<pre><code>c=Class()
</code></pre>
<p>I want c.v... | 4 | 2009-01-14T16:55:48Z | 443,835 | <p>I am unaware of a way to access a variable's name programmatically without using deep reflection and a debugger. I do not think the information is available at runtime.</p>
<p>If you want to give instances a (unique?) name, you should probably make the initializer accept an extra argument.</p>
<pre><code>def __in... | 1 | 2009-01-14T17:05:25Z | [
"python",
"instance",
"instantiation"
] |
Addressing instance name string in __init__(self) in Python | 443,775 | <p>I am doing something like this:</p>
<pre><code>class Class(object):
def __init__(self):
self.var=#new instance name string#
</code></pre>
<p>How do I make the __ init __ method of my instance to use the instance name string for 'c'? Say in case:</p>
<pre><code>c=Class()
</code></pre>
<p>I want c.v... | 4 | 2009-01-14T16:55:48Z | 443,836 | <p>You can't (short of incredible hacks like examining the stack frame and inspecting the bytecode). There may not even <em>be</em> a name, or there could be multiple such names. What should be given for the following code fragments for instance:</p>
<pre><code>l = [Class(), Class()]
a=b=c=d=Class()
</code></pre>
| 2 | 2009-01-14T17:05:28Z | [
"python",
"instance",
"instantiation"
] |
Addressing instance name string in __init__(self) in Python | 443,775 | <p>I am doing something like this:</p>
<pre><code>class Class(object):
def __init__(self):
self.var=#new instance name string#
</code></pre>
<p>How do I make the __ init __ method of my instance to use the instance name string for 'c'? Say in case:</p>
<pre><code>c=Class()
</code></pre>
<p>I want c.v... | 4 | 2009-01-14T16:55:48Z | 443,839 | <p>I don't think this would be possible because the assignment to the variable of your new instance occours after the object is fully constructed and initialized and so you don't know the variable name it will be assigned to within <strong>init</strong> method</p>
| 2 | 2009-01-14T17:06:06Z | [
"python",
"instance",
"instantiation"
] |
Addressing instance name string in __init__(self) in Python | 443,775 | <p>I am doing something like this:</p>
<pre><code>class Class(object):
def __init__(self):
self.var=#new instance name string#
</code></pre>
<p>How do I make the __ init __ method of my instance to use the instance name string for 'c'? Say in case:</p>
<pre><code>c=Class()
</code></pre>
<p>I want c.v... | 4 | 2009-01-14T16:55:48Z | 443,841 | <p>You can't do this. The reason for this is that the object of the class is created first, and only afterwards is this object bound to the name of the instance.</p>
| 3 | 2009-01-14T17:07:24Z | [
"python",
"instance",
"instantiation"
] |
Addressing instance name string in __init__(self) in Python | 443,775 | <p>I am doing something like this:</p>
<pre><code>class Class(object):
def __init__(self):
self.var=#new instance name string#
</code></pre>
<p>How do I make the __ init __ method of my instance to use the instance name string for 'c'? Say in case:</p>
<pre><code>c=Class()
</code></pre>
<p>I want c.v... | 4 | 2009-01-14T16:55:48Z | 443,843 | <p>This is a scope issue, you can't do what you're asking. Because c would be declared outside your class' scope, your instance is unaware of what its been named in code.</p>
<p>Perhaps if you can provide a broader explanation of what you're trying to accomplish a better solution can be suggested.</p>
| 1 | 2009-01-14T17:07:36Z | [
"python",
"instance",
"instantiation"
] |
Addressing instance name string in __init__(self) in Python | 443,775 | <p>I am doing something like this:</p>
<pre><code>class Class(object):
def __init__(self):
self.var=#new instance name string#
</code></pre>
<p>How do I make the __ init __ method of my instance to use the instance name string for 'c'? Say in case:</p>
<pre><code>c=Class()
</code></pre>
<p>I want c.v... | 4 | 2009-01-14T16:55:48Z | 443,868 | <p>Python doesn't have variables, it has <a href="http://effbot.org/zone/python-objects.htm" rel="nofollow">objects and names</a>. When you do </p>
<pre><code>c = Class()
</code></pre>
<p>you're doing two things:</p>
<ol>
<li>Creating a new object of type <code>Class</code></li>
<li>Binding the object to the name <c... | 7 | 2009-01-14T17:13:51Z | [
"python",
"instance",
"instantiation"
] |
Addressing instance name string in __init__(self) in Python | 443,775 | <p>I am doing something like this:</p>
<pre><code>class Class(object):
def __init__(self):
self.var=#new instance name string#
</code></pre>
<p>How do I make the __ init __ method of my instance to use the instance name string for 'c'? Say in case:</p>
<pre><code>c=Class()
</code></pre>
<p>I want c.v... | 4 | 2009-01-14T16:55:48Z | 444,624 | <p>To persist data objects you need to use the database record's unique ID.</p>
<p><strong>pesudo code because I don't know what database module you're using</strong></p>
<pre><code>import db # assume this is your db module
class Class(object):
def __init__(self):
self.id = None
self.name = None
... | 1 | 2009-01-14T20:55:08Z | [
"python",
"instance",
"instantiation"
] |
Addressing instance name string in __init__(self) in Python | 443,775 | <p>I am doing something like this:</p>
<pre><code>class Class(object):
def __init__(self):
self.var=#new instance name string#
</code></pre>
<p>How do I make the __ init __ method of my instance to use the instance name string for 'c'? Say in case:</p>
<pre><code>c=Class()
</code></pre>
<p>I want c.v... | 4 | 2009-01-14T16:55:48Z | 2,160,512 | <p>I have the same thought several years ago. This is somekind of neat feature, but the language creator doesn't provide it. And I thought they are all fool to not discover this great feature.</p>
<p>But then come to think about that. I think the logic is impossible. say:</p>
<pre><code>class Class(object):
def _... | 0 | 2010-01-29T07:25:39Z | [
"python",
"instance",
"instantiation"
] |
python, index errors | 443,813 | <p>I've got some code which draws data from an xml file but it seems to have randomly starting throwing;</p>
<pre><code>Traceback (most recent call last):
File "C:\Users\mike\Documents\python\arl xml\turn 24 reader", line 52, in <module>
unitCount = getText(evoNode.getElementsByTagName("count")[0].childN... | 1 | 2009-01-14T17:01:45Z | 443,845 | <p>A simple idea: check if <code>evoNode.getElementsByTagName("count")</code> returns a non-empty list:</p>
<pre><code>counts = evoNode.getElementsByTagName("count")
if counts:
unitCount = getText(counts[0].childNodes)
</code></pre>
<p>Of course, the check should be applied to all the lists retrieved by your code... | 2 | 2009-01-14T17:08:01Z | [
"python",
"xml",
"for-loop"
] |
python, index errors | 443,813 | <p>I've got some code which draws data from an xml file but it seems to have randomly starting throwing;</p>
<pre><code>Traceback (most recent call last):
File "C:\Users\mike\Documents\python\arl xml\turn 24 reader", line 52, in <module>
unitCount = getText(evoNode.getElementsByTagName("count")[0].childN... | 1 | 2009-01-14T17:01:45Z | 443,871 | <p>As gimel said you should check getElementsByTagName("count") if it returns non empty list, but back to your problem:</p>
<p>If you said that it was working before then my guess that the problem is with the source where you get the XML.</p>
| 1 | 2009-01-14T17:14:38Z | [
"python",
"xml",
"for-loop"
] |
Python: Callbacks, Delegates, ... ? What is common? | 443,885 | <p>Just want to know what's the common way to react on events in python. There are several ways in other languages like callback functions, delegates, listener-structures and so on.
Is there a common way? Which default language concepts or additional modules are there and which can you recommend?</p>
| 21 | 2009-01-14T17:20:28Z | 443,934 | <p>Personally, I've only seen callbacks used. However, I haven't seen that much event driven python code so YMMV.</p>
| 0 | 2009-01-14T17:34:58Z | [
"python",
"events",
"delegates",
"callback"
] |
Python: Callbacks, Delegates, ... ? What is common? | 443,885 | <p>Just want to know what's the common way to react on events in python. There are several ways in other languages like callback functions, delegates, listener-structures and so on.
Is there a common way? Which default language concepts or additional modules are there and which can you recommend?</p>
| 21 | 2009-01-14T17:20:28Z | 443,972 | <p>I can't speak for common approaches, but <a href="http://www.suttoncourtenay.org.uk/duncan/accu/pythonpatterns.html" rel="nofollow" title="Patterns in Python">this page</a> (actual copy is unavailable) has an implementation of the observer pattern that I like.</p>
<p>Here's the Internet Archive link:
<a href="http:... | 3 | 2009-01-14T17:43:22Z | [
"python",
"events",
"delegates",
"callback"
] |
Python: Callbacks, Delegates, ... ? What is common? | 443,885 | <p>Just want to know what's the common way to react on events in python. There are several ways in other languages like callback functions, delegates, listener-structures and so on.
Is there a common way? Which default language concepts or additional modules are there and which can you recommend?</p>
| 21 | 2009-01-14T17:20:28Z | 444,003 | <p>I have seen listeners and callbacks used. But AFAIK there is no Python way. They should be equally feasible if the application in question is suitable.</p>
| 0 | 2009-01-14T17:50:22Z | [
"python",
"events",
"delegates",
"callback"
] |
Python: Callbacks, Delegates, ... ? What is common? | 443,885 | <p>Just want to know what's the common way to react on events in python. There are several ways in other languages like callback functions, delegates, listener-structures and so on.
Is there a common way? Which default language concepts or additional modules are there and which can you recommend?</p>
| 21 | 2009-01-14T17:20:28Z | 444,057 | <p>Personally I don't see a difference between callbacks, listeners, and delegates.</p>
<p>The <a href="http://en.wikipedia.org/wiki/Observer_pattern">observer pattern</a> (a.k.a listeners, a.k.a "multiple callbacks") is easy to implement - just hold a list of observers, and add or remove callables from it. These call... | 14 | 2009-01-14T18:07:35Z | [
"python",
"events",
"delegates",
"callback"
] |
Python: Callbacks, Delegates, ... ? What is common? | 443,885 | <p>Just want to know what's the common way to react on events in python. There are several ways in other languages like callback functions, delegates, listener-structures and so on.
Is there a common way? Which default language concepts or additional modules are there and which can you recommend?</p>
| 21 | 2009-01-14T17:20:28Z | 444,108 | <p>It all depends on the level of complexity your application requires. For simple events, callbacks will probably do. For more complex patterns and decoupled levels you should use some kind of a publish-subscribe implementation, such as <a href="http://pydispatcher.sourceforge.net/" rel="nofollow">PyDispatcher</a> or ... | 1 | 2009-01-14T18:20:02Z | [
"python",
"events",
"delegates",
"callback"
] |
Python: Callbacks, Delegates, ... ? What is common? | 443,885 | <p>Just want to know what's the common way to react on events in python. There are several ways in other languages like callback functions, delegates, listener-structures and so on.
Is there a common way? Which default language concepts or additional modules are there and which can you recommend?</p>
| 21 | 2009-01-14T17:20:28Z | 444,154 | <p>Most of the Python libraries I have used implement a callback model for their event notifications, which I think suits the language fairly well. <a href="http://www.pygtk.org/" rel="nofollow">Pygtk</a> does this by deriving all objects from <a href="http://www.pygtk.org/docs/pygobject/class-gobject.html" rel="nofol... | 1 | 2009-01-14T18:33:55Z | [
"python",
"events",
"delegates",
"callback"
] |
Python: Callbacks, Delegates, ... ? What is common? | 443,885 | <p>Just want to know what's the common way to react on events in python. There are several ways in other languages like callback functions, delegates, listener-structures and so on.
Is there a common way? Which default language concepts or additional modules are there and which can you recommend?</p>
| 21 | 2009-01-14T17:20:28Z | 445,865 | <p>The <code>matplotlib.cbook</code> module contains a class <code>CallbackRegistry</code> that you might want to have a look at. From the <a href="http://matplotlib.sourceforge.net/api/cbook_api.html" rel="nofollow">documentation</a>:</p>
<pre>
Handle registering and disconnecting for a set of signals and
callbacks:
... | 0 | 2009-01-15T06:39:56Z | [
"python",
"events",
"delegates",
"callback"
] |
Python: Callbacks, Delegates, ... ? What is common? | 443,885 | <p>Just want to know what's the common way to react on events in python. There are several ways in other languages like callback functions, delegates, listener-structures and so on.
Is there a common way? Which default language concepts or additional modules are there and which can you recommend?</p>
| 21 | 2009-01-14T17:20:28Z | 851,099 | <p>I'm searching for an implementation to register and handle events in Python. My only experience is with <a href="http://www.pygtk.org/docs/pygobject/class-gobject.html" rel="nofollow">Gobject</a>, but have only used it with PyGtk. It is flexible, but might be overly complicated for some users. I have come across of ... | 0 | 2009-05-12T04:13:31Z | [
"python",
"events",
"delegates",
"callback"
] |
Why don't Django admin "Today" and "Now" buttons show up in Safari? | 443,920 | <p>I'm developing a Django application that contains a model with a date/time field. On my local copy of the application, the admin page for that particular model shows this for the date/time field:</p>
<p><img src="http://www.cs.wm.edu/~mpd/images/bugs/django-date-local.png" alt="alt text" /></p>
<p>This is as expec... | 3 | 2009-01-14T17:30:34Z | 443,992 | <p>Check the media location, permissions and setup on your deployment server.</p>
<p><a href="http://www.djangobook.com/en/1.0/chapter20/" rel="nofollow">http://www.djangobook.com/en/1.0/chapter20/</a></p>
| 0 | 2009-01-14T17:47:43Z | [
"javascript",
"python",
"django",
"safari",
"webkit"
] |
Why don't Django admin "Today" and "Now" buttons show up in Safari? | 443,920 | <p>I'm developing a Django application that contains a model with a date/time field. On my local copy of the application, the admin page for that particular model shows this for the date/time field:</p>
<p><img src="http://www.cs.wm.edu/~mpd/images/bugs/django-date-local.png" alt="alt text" /></p>
<p>This is as expec... | 3 | 2009-01-14T17:30:34Z | 444,015 | <p>It seems like you have admin media missing (hence js and images aren't loading). I generally do following.</p>
<p>in <code>settings.py</code></p>
<pre><code>ADMIN_MEDIA_PREFIX = '/media/admin/'
</code></pre>
<p>Then I symlink path of <code>django.contrib.admin.media</code> within my <code>media</code> dir. Say:</... | 1 | 2009-01-14T17:55:36Z | [
"javascript",
"python",
"django",
"safari",
"webkit"
] |
Why don't Django admin "Today" and "Now" buttons show up in Safari? | 443,920 | <p>I'm developing a Django application that contains a model with a date/time field. On my local copy of the application, the admin page for that particular model shows this for the date/time field:</p>
<p><img src="http://www.cs.wm.edu/~mpd/images/bugs/django-date-local.png" alt="alt text" /></p>
<p>This is as expec... | 3 | 2009-01-14T17:30:34Z | 444,052 | <p>Have you tried checking out firebug's NET tab to see if the admin javascript/css/image files are all loading correctly?</p>
<p>I had that problem once.</p>
<p>Compare all those files from the dev server against the production server.</p>
| 0 | 2009-01-14T18:06:30Z | [
"javascript",
"python",
"django",
"safari",
"webkit"
] |
Why don't Django admin "Today" and "Now" buttons show up in Safari? | 443,920 | <p>I'm developing a Django application that contains a model with a date/time field. On my local copy of the application, the admin page for that particular model shows this for the date/time field:</p>
<p><img src="http://www.cs.wm.edu/~mpd/images/bugs/django-date-local.png" alt="alt text" /></p>
<p>This is as expec... | 3 | 2009-01-14T17:30:34Z | 636,182 | <p>If you're getting 304 on those files. Flush your browser's cache and try again.</p>
<p>If it doesn't load again anyway, make sure you are getting 200 OK.</p>
| 2 | 2009-03-11T20:19:08Z | [
"javascript",
"python",
"django",
"safari",
"webkit"
] |
Why don't Django admin "Today" and "Now" buttons show up in Safari? | 443,920 | <p>I'm developing a Django application that contains a model with a date/time field. On my local copy of the application, the admin page for that particular model shows this for the date/time field:</p>
<p><img src="http://www.cs.wm.edu/~mpd/images/bugs/django-date-local.png" alt="alt text" /></p>
<p>This is as expec... | 3 | 2009-01-14T17:30:34Z | 648,681 | <p>I think you have to look at what is different between your firefox configuration and safary config</p>
<p>Off the top of my head:</p>
<ul>
<li><p>One could be configured to use a proxy (messing with the trafic) the other not. Make sure the configuration is the same in both.</p></li>
<li><p>Safari could have cached... | 3 | 2009-03-15T22:25:08Z | [
"javascript",
"python",
"django",
"safari",
"webkit"
] |
How to create python bytes object from long hex string? | 443,967 | <p>I have a long sequence of hex digits in a string, such as </p>
<blockquote>
<p>000000000000484240FA063DE5D0B744ADBED63A81FAEA390000C8428640A43D5005BD44</p>
</blockquote>
<p>only much longer, several kilobytes. Is there a builtin way to convert this to a bytes object in python 2.6/3?</p>
| 39 | 2009-01-14T17:42:50Z | 443,985 | <p>Try the <a href="http://doc.astro-wise.org/binascii.html#-unhexlify">binascii module</a></p>
<pre><code>from binascii import unhexlify
b = unhexlify(myhexstr)
</code></pre>
| 26 | 2009-01-14T17:46:38Z | [
"python",
"hex",
"byte"
] |
How to create python bytes object from long hex string? | 443,967 | <p>I have a long sequence of hex digits in a string, such as </p>
<blockquote>
<p>000000000000484240FA063DE5D0B744ADBED63A81FAEA390000C8428640A43D5005BD44</p>
</blockquote>
<p>only much longer, several kilobytes. Is there a builtin way to convert this to a bytes object in python 2.6/3?</p>
| 39 | 2009-01-14T17:42:50Z | 443,990 | <p>You can do this with the hex codec. ie:</p>
<pre><code>>>> s='000000000000484240FA063DE5D0B744ADBED63A81FAEA390000C8428640A43D5005BD44'
>>> s.decode('hex')
'\x00\x00\x00\x00\x00\x00HB@\xfa\x06=\xe5\xd0\xb7D\xad\xbe\xd6:\x81\xfa\xea9\x00\x00\xc8B\x86@\xa4=P\x05\xbdD'
</code></pre>
| 37 | 2009-01-14T17:47:20Z | [
"python",
"hex",
"byte"
] |
How to create python bytes object from long hex string? | 443,967 | <p>I have a long sequence of hex digits in a string, such as </p>
<blockquote>
<p>000000000000484240FA063DE5D0B744ADBED63A81FAEA390000C8428640A43D5005BD44</p>
</blockquote>
<p>only much longer, several kilobytes. Is there a builtin way to convert this to a bytes object in python 2.6/3?</p>
| 39 | 2009-01-14T17:42:50Z | 444,005 | <pre><code>result = bytes.fromhex(some_hex_string)
</code></pre>
| 21 | 2009-01-14T17:50:38Z | [
"python",
"hex",
"byte"
] |
How to create python bytes object from long hex string? | 443,967 | <p>I have a long sequence of hex digits in a string, such as </p>
<blockquote>
<p>000000000000484240FA063DE5D0B744ADBED63A81FAEA390000C8428640A43D5005BD44</p>
</blockquote>
<p>only much longer, several kilobytes. Is there a builtin way to convert this to a bytes object in python 2.6/3?</p>
| 39 | 2009-01-14T17:42:50Z | 17,160,152 | <p>Works in Python 2.7 and higher including python3:</p>
<pre><code>result = bytearray.fromhex('deadbeef')
</code></pre>
<p><strong>Note:</strong> There seems to be a bug with the <code>bytearray.fromhex()</code> function in Python 2.6. The python.org documentation states that the function accepts a string as an argu... | 18 | 2013-06-18T03:37:20Z | [
"python",
"hex",
"byte"
] |
How to create python bytes object from long hex string? | 443,967 | <p>I have a long sequence of hex digits in a string, such as </p>
<blockquote>
<p>000000000000484240FA063DE5D0B744ADBED63A81FAEA390000C8428640A43D5005BD44</p>
</blockquote>
<p>only much longer, several kilobytes. Is there a builtin way to convert this to a bytes object in python 2.6/3?</p>
| 39 | 2009-01-14T17:42:50Z | 29,030,879 | <pre><code>import binascii
binascii.b2a_hex(obj)
</code></pre>
| -1 | 2015-03-13T11:19:26Z | [
"python",
"hex",
"byte"
] |
python - readable list of objects | 444,058 | <p>This is probably a kinda commonly asked question but I could do with help on this. I have a list of class objects and I'm trying to figure out how to make it print an item from that class but rather than desplaying in the;</p>
<pre><code><__main__.evolutions instance at 0x01B8EA08>
</code></pre>
<p>but inste... | 5 | 2009-01-14T18:07:54Z | 444,070 | <p>Checkout the __str__() and __repr__() methods.</p>
<p>See <a href="http://docs.python.org/reference/datamodel.html#object.__repr__" rel="nofollow">http://docs.python.org/reference/datamodel.html#object.__repr__</a></p>
| 4 | 2009-01-14T18:11:47Z | [
"python",
"list"
] |
python - readable list of objects | 444,058 | <p>This is probably a kinda commonly asked question but I could do with help on this. I have a list of class objects and I'm trying to figure out how to make it print an item from that class but rather than desplaying in the;</p>
<pre><code><__main__.evolutions instance at 0x01B8EA08>
</code></pre>
<p>but inste... | 5 | 2009-01-14T18:07:54Z | 444,071 | <p>You'll want to override your class's "to string" method:</p>
<pre><code>class Foo:
def __str__(self):
return "String representation of me"
</code></pre>
| 4 | 2009-01-14T18:11:54Z | [
"python",
"list"
] |
python - readable list of objects | 444,058 | <p>This is probably a kinda commonly asked question but I could do with help on this. I have a list of class objects and I'm trying to figure out how to make it print an item from that class but rather than desplaying in the;</p>
<pre><code><__main__.evolutions instance at 0x01B8EA08>
</code></pre>
<p>but inste... | 5 | 2009-01-14T18:07:54Z | 444,073 | <p>If you want to just display a particular attribute of each class instance, you can do</p>
<pre><code>print([obj.attr for obj in my_list_of_objs])
</code></pre>
<p>Which will print out the <code>attr</code> attribute of each object in the list <code>my_list_of_objs</code>. Alternatively, you can define the <code>_... | 8 | 2009-01-14T18:12:20Z | [
"python",
"list"
] |
python - readable list of objects | 444,058 | <p>This is probably a kinda commonly asked question but I could do with help on this. I have a list of class objects and I'm trying to figure out how to make it print an item from that class but rather than desplaying in the;</p>
<pre><code><__main__.evolutions instance at 0x01B8EA08>
</code></pre>
<p>but inste... | 5 | 2009-01-14T18:07:54Z | 444,105 | <p>You need to override either the <a href="http://docs.python.org/reference/datamodel.html#object.__str__" rel="nofollow"><code>__str__</code></a>, or <a href="http://docs.python.org/reference/datamodel.html#object.__repr__" rel="nofollow"><code>__repr__</code></a> methods of your object[s]</p>
| 2 | 2009-01-14T18:19:54Z | [
"python",
"list"
] |
python - readable list of objects | 444,058 | <p>This is probably a kinda commonly asked question but I could do with help on this. I have a list of class objects and I'm trying to figure out how to make it print an item from that class but rather than desplaying in the;</p>
<pre><code><__main__.evolutions instance at 0x01B8EA08>
</code></pre>
<p>but inste... | 5 | 2009-01-14T18:07:54Z | 803,845 | <p>My preference is to define a <code>__repr__</code> function that can reconstruct the object (whenever possible). Unless you have a <code>__str__</code> as well, both <code>repr()</code> and <code>str()</code> will call this method.</p>
<p>So for example</p>
<pre><code>class Foo(object):
def __init__(self, a, b... | 1 | 2009-04-29T19:17:38Z | [
"python",
"list"
] |
sqlalchemy, turning a list of IDs to a list of objects | 444,475 | <p>I have sequence of IDs I want to retrieve. It's simple:</p>
<pre><code>session.query(Record).filter(Record.id.in_(seq)).all()
</code></pre>
<p>Is there a better way to do it?</p>
| 17 | 2009-01-14T20:08:32Z | 444,524 | <p>I'd recommend to take a look at the SQL it produces. You can just print str(query) to see it.</p>
<p>I'm not aware of an ideal way of doing it with standard SQL.</p>
| 1 | 2009-01-14T20:21:40Z | [
"python",
"sqlalchemy"
] |
sqlalchemy, turning a list of IDs to a list of objects | 444,475 | <p>I have sequence of IDs I want to retrieve. It's simple:</p>
<pre><code>session.query(Record).filter(Record.id.in_(seq)).all()
</code></pre>
<p>Is there a better way to do it?</p>
| 17 | 2009-01-14T20:08:32Z | 457,057 | <p>Your code is absolutety fine. </p>
<p><code>IN</code> is like a bunch of <code>X=Y</code> joined with <code>OR</code> and is pretty fast in contemporary databases. </p>
<p>However, if your list of IDs is long, you could make the query a bit more efficient by passing a sub-query returning the list of IDs.</p>
| 10 | 2009-01-19T09:49:39Z | [
"python",
"sqlalchemy"
] |
sqlalchemy, turning a list of IDs to a list of objects | 444,475 | <p>I have sequence of IDs I want to retrieve. It's simple:</p>
<pre><code>session.query(Record).filter(Record.id.in_(seq)).all()
</code></pre>
<p>Is there a better way to do it?</p>
| 17 | 2009-01-14T20:08:32Z | 21,267,667 | <p>If you use composite primary keys, you can use <code>tuple_</code>, as in</p>
<pre><code>from sqlalchemy import tuple_
session.query(Record).filter(tuple_(Record.id1, Record.id2).in_(seq)).all()
</code></pre>
<p>Note that this is not available on SQLite (see <a href="http://docs.sqlalchemy.org/en/rel_0_9/core/sqle... | 1 | 2014-01-21T19:49:20Z | [
"python",
"sqlalchemy"
] |
sqlalchemy, turning a list of IDs to a list of objects | 444,475 | <p>I have sequence of IDs I want to retrieve. It's simple:</p>
<pre><code>session.query(Record).filter(Record.id.in_(seq)).all()
</code></pre>
<p>Is there a better way to do it?</p>
| 17 | 2009-01-14T20:08:32Z | 21,267,811 | <p>There is one other way; If it's reasonable to expect that the objects in question are already loaded into the session; you've accessed them before in the same transaction, you can instead do:</p>
<pre><code>map(session.query(Record).get, seq)
</code></pre>
<p>In the case where those objects are already present, t... | 1 | 2014-01-21T19:57:52Z | [
"python",
"sqlalchemy"
] |
sqlalchemy, turning a list of IDs to a list of objects | 444,475 | <p>I have sequence of IDs I want to retrieve. It's simple:</p>
<pre><code>session.query(Record).filter(Record.id.in_(seq)).all()
</code></pre>
<p>Is there a better way to do it?</p>
| 17 | 2009-01-14T20:08:32Z | 28,370,511 | <p>The code as is is completely fine. However, someone is asking me for some system of hedging between the two approaches of doing a big IN vs. using get() for individual IDs.</p>
<p>If someone is really trying to avoid the SELECT, then the best way to do that is to set up the objects you need in memory ahead of time... | 4 | 2015-02-06T16:37:32Z | [
"python",
"sqlalchemy"
] |
How are debug consoles implemented in Python? | 444,509 | <p>I've seen a couple of Python IDE's (e.g. PyDev Extensions, WingIDE) that provide a debug console - an interactive terminal that runs in the context of the method where the breakpoint is. This lets you print members, call other methods and see the results, and redefine methods to try to fix bugs. Cool.</p>
<p>Can an... | 10 | 2009-01-14T20:17:06Z | 444,918 | <p>You could try looking at the python debugger pdb. It's like gdb in how you use it, but implemented in pure python. Have a look for pdb.py in your python install directory.</p>
| 6 | 2009-01-14T22:18:13Z | [
"python",
"debugging",
"interactive"
] |
How are debug consoles implemented in Python? | 444,509 | <p>I've seen a couple of Python IDE's (e.g. PyDev Extensions, WingIDE) that provide a debug console - an interactive terminal that runs in the context of the method where the breakpoint is. This lets you print members, call other methods and see the results, and redefine methods to try to fix bugs. Cool.</p>
<p>Can an... | 10 | 2009-01-14T20:17:06Z | 445,020 | <p><a href="http://docs.python.org/3.0/library/functions.html#input" rel="nofollow">http://docs.python.org/3.0/library/functions.html#input</a><br>
<a href="http://docs.python.org/3.0/library/functions.html#eval" rel="nofollow">http://docs.python.org/3.0/library/functions.html#eval</a></p>
<pre><code>def start_interpr... | 2 | 2009-01-14T22:53:16Z | [
"python",
"debugging",
"interactive"
] |
How are debug consoles implemented in Python? | 444,509 | <p>I've seen a couple of Python IDE's (e.g. PyDev Extensions, WingIDE) that provide a debug console - an interactive terminal that runs in the context of the method where the breakpoint is. This lets you print members, call other methods and see the results, and redefine methods to try to fix bugs. Cool.</p>
<p>Can an... | 10 | 2009-01-14T20:17:06Z | 445,099 | <p>Python has a debugger framework in the <a href="http://docs.python.org/library/bdb.html" rel="nofollow">bdb module</a>. I'm not sure if the IDE's you list use it but it's certainly possible to implement a full Python debugger with it.</p>
| 0 | 2009-01-14T23:29:13Z | [
"python",
"debugging",
"interactive"
] |
How are debug consoles implemented in Python? | 444,509 | <p>I've seen a couple of Python IDE's (e.g. PyDev Extensions, WingIDE) that provide a debug console - an interactive terminal that runs in the context of the method where the breakpoint is. This lets you print members, call other methods and see the results, and redefine methods to try to fix bugs. Cool.</p>
<p>Can an... | 10 | 2009-01-14T20:17:06Z | 447,869 | <p>Right, I'm ashamed to admit it's actually in the documentation for InteractiveConsole after all. You can make it run in the local context by passing in the result of the locals() function to the InteractiveConsole constructor. I couldn't find a way to close the InteractiveConsole without killing the application, so ... | 3 | 2009-01-15T18:25:28Z | [
"python",
"debugging",
"interactive"
] |
How are debug consoles implemented in Python? | 444,509 | <p>I've seen a couple of Python IDE's (e.g. PyDev Extensions, WingIDE) that provide a debug console - an interactive terminal that runs in the context of the method where the breakpoint is. This lets you print members, call other methods and see the results, and redefine methods to try to fix bugs. Cool.</p>
<p>Can an... | 10 | 2009-01-14T20:17:06Z | 2,141,143 | <p>If you want to experiment with your own Python console then this is a nice start:</p>
<pre><code>cmd = None
while cmd != 'exit':
cmd = raw_input('>>> ')
try:
exec(cmd)
except:
print 'exception'
</code></pre>
<p>But for real work use the InteractiveConsole instead.</p>
| 0 | 2010-01-26T17:14:48Z | [
"python",
"debugging",
"interactive"
] |
convert a string of bytes into an int (python) | 444,591 | <p>How can I convert a string of bytes into an int in python? </p>
<p>Say like this: <code>'y\xcc\xa6\xbb'</code></p>
<p>I came up with a clever/stupid way of doing it:</p>
<pre><code>sum(ord(c) << (i * 8) for i, c in enumerate('y\xcc\xa6\xbb'[::-1]))
</code></pre>
<p>I know there has to be something builtin ... | 76 | 2009-01-14T20:46:17Z | 444,610 | <p>You can also use the <code>struct</code> module to do this:</p>
<pre><code>>>> struct.unpack("<L", "y\xcc\xa6\xbb")[0]
3148270713L
</code></pre>
| 61 | 2009-01-14T20:52:39Z | [
"python",
"string",
"bytearray"
] |
convert a string of bytes into an int (python) | 444,591 | <p>How can I convert a string of bytes into an int in python? </p>
<p>Say like this: <code>'y\xcc\xa6\xbb'</code></p>
<p>I came up with a clever/stupid way of doing it:</p>
<pre><code>sum(ord(c) << (i * 8) for i, c in enumerate('y\xcc\xa6\xbb'[::-1]))
</code></pre>
<p>I know there has to be something builtin ... | 76 | 2009-01-14T20:46:17Z | 444,814 | <p>As Greg said, you can use struct if you are dealing with binary values, but if you just have a "hex number" but in byte format you might want to just convert it like:</p>
<pre><code>s = 'y\xcc\xa6\xbb'
num = int(s.encode('hex'), 16)
</code></pre>
<p>...this is the same as:</p>
<pre><code>num = struct.unpack(">L",... | 51 | 2009-01-14T21:42:52Z | [
"python",
"string",
"bytearray"
] |
convert a string of bytes into an int (python) | 444,591 | <p>How can I convert a string of bytes into an int in python? </p>
<p>Say like this: <code>'y\xcc\xa6\xbb'</code></p>
<p>I came up with a clever/stupid way of doing it:</p>
<pre><code>sum(ord(c) << (i * 8) for i, c in enumerate('y\xcc\xa6\xbb'[::-1]))
</code></pre>
<p>I know there has to be something builtin ... | 76 | 2009-01-14T20:46:17Z | 444,855 | <pre><code>import array
integerValue = array.array("I", 'y\xcc\xa6\xbb')[0]
</code></pre>
<p>Warning: the above is strongly platform-specific. Both the "I" specifier and the endianness of the string->int conversion are dependent on your particular Python implementation. But if you want to convert many integers/strings... | 6 | 2009-01-14T21:55:37Z | [
"python",
"string",
"bytearray"
] |
convert a string of bytes into an int (python) | 444,591 | <p>How can I convert a string of bytes into an int in python? </p>
<p>Say like this: <code>'y\xcc\xa6\xbb'</code></p>
<p>I came up with a clever/stupid way of doing it:</p>
<pre><code>sum(ord(c) << (i * 8) for i, c in enumerate('y\xcc\xa6\xbb'[::-1]))
</code></pre>
<p>I know there has to be something builtin ... | 76 | 2009-01-14T20:46:17Z | 9,634,417 | <p>In Python 3.2 and later, use</p>
<pre><code>>>> int.from_bytes(b'y\xcc\xa6\xbb', byteorder='big')
2043455163
</code></pre>
<p>or</p>
<pre><code>>>> int.from_bytes(b'y\xcc\xa6\xbb', byteorder='little')
3148270713
</code></pre>
<p>according to the endianness of your byte-string.</p>
<p>This also... | 138 | 2012-03-09T12:56:38Z | [
"python",
"string",
"bytearray"
] |
convert a string of bytes into an int (python) | 444,591 | <p>How can I convert a string of bytes into an int in python? </p>
<p>Say like this: <code>'y\xcc\xa6\xbb'</code></p>
<p>I came up with a clever/stupid way of doing it:</p>
<pre><code>sum(ord(c) << (i * 8) for i, c in enumerate('y\xcc\xa6\xbb'[::-1]))
</code></pre>
<p>I know there has to be something builtin ... | 76 | 2009-01-14T20:46:17Z | 22,980,298 | <p>I use the following function to convert data between int, hex and bytes.</p>
<pre><code>def bytes2int(str):
return int(str.encode('hex'), 16)
def bytes2hex(str):
return '0x'+str.encode('hex')
def int2bytes(i):
h = int2hex(i)
return hex2bytes(h)
def int2hex(i):
return hex(i)
def hex2int(h):
if len(h) > ... | 5 | 2014-04-10T06:35:06Z | [
"python",
"string",
"bytearray"
] |
convert a string of bytes into an int (python) | 444,591 | <p>How can I convert a string of bytes into an int in python? </p>
<p>Say like this: <code>'y\xcc\xa6\xbb'</code></p>
<p>I came up with a clever/stupid way of doing it:</p>
<pre><code>sum(ord(c) << (i * 8) for i, c in enumerate('y\xcc\xa6\xbb'[::-1]))
</code></pre>
<p>I know there has to be something builtin ... | 76 | 2009-01-14T20:46:17Z | 32,001,227 | <p>In Python 2.x, you could use the format specifiers <code><B</code> for unsigned bytes, and <code><b</code> for signed bytes with <code>struct.unpack</code>/<code>struct.pack</code>.</p>
<p>E.g:</p>
<p>Let <code>x</code> = <code>'\xff\x10\x11'</code></p>
<p><strike><code>data_ints = [struct.unpack('<B', x... | 2 | 2015-08-14T02:03:23Z | [
"python",
"string",
"bytearray"
] |
convert a string of bytes into an int (python) | 444,591 | <p>How can I convert a string of bytes into an int in python? </p>
<p>Say like this: <code>'y\xcc\xa6\xbb'</code></p>
<p>I came up with a clever/stupid way of doing it:</p>
<pre><code>sum(ord(c) << (i * 8) for i, c in enumerate('y\xcc\xa6\xbb'[::-1]))
</code></pre>
<p>I know there has to be something builtin ... | 76 | 2009-01-14T20:46:17Z | 33,585,619 | <p>I was struggling to find a solution for arbitrary length byte sequences that would work under Python 2.x. Finally I wrote this one, it's a bit hacky because it performs a string conversion, but it works.</p>
<h1>Function for Python 2.x, arbitrary length</h1>
<pre><code>def signedbytes(data):
"""Convert a bytea... | 0 | 2015-11-07T17:27:15Z | [
"python",
"string",
"bytearray"
] |
convert a string of bytes into an int (python) | 444,591 | <p>How can I convert a string of bytes into an int in python? </p>
<p>Say like this: <code>'y\xcc\xa6\xbb'</code></p>
<p>I came up with a clever/stupid way of doing it:</p>
<pre><code>sum(ord(c) << (i * 8) for i, c in enumerate('y\xcc\xa6\xbb'[::-1]))
</code></pre>
<p>I know there has to be something builtin ... | 76 | 2009-01-14T20:46:17Z | 35,634,239 | <p>int.from_bytes is the best solution if you are at version >=3.2.
The "struct.unpack" solution requires a string so it will not apply to arrays of bytes.
Here is another solution:</p>
<pre><code>def bytes2int( tb, order='big'):
if order == 'big': seq=[0,1,2,3]
elif order == 'little': seq=[3,2,1,0]
i = 0
... | 1 | 2016-02-25T17:30:35Z | [
"python",
"string",
"bytearray"
] |
convert a string of bytes into an int (python) | 444,591 | <p>How can I convert a string of bytes into an int in python? </p>
<p>Say like this: <code>'y\xcc\xa6\xbb'</code></p>
<p>I came up with a clever/stupid way of doing it:</p>
<pre><code>sum(ord(c) << (i * 8) for i, c in enumerate('y\xcc\xa6\xbb'[::-1]))
</code></pre>
<p>I know there has to be something builtin ... | 76 | 2009-01-14T20:46:17Z | 39,713,066 | <pre><code>>>> reduce(lambda s, x: s*256 + x, bytearray("y\xcc\xa6\xbb"))
2043455163
</code></pre>
<p>Test 1: inverse:</p>
<pre><code>>>> hex(2043455163)
'0x79cca6bb'
</code></pre>
<p>Test 2: Number of bytes > 8:</p>
<pre><code>>>> reduce(lambda s, x: s*256 + x, bytearray("AAAAAAAAAAAAAAA... | 0 | 2016-09-26T21:58:58Z | [
"python",
"string",
"bytearray"
] |
How to make a wx Toolbar buttons larger? | 445,037 | <p>I've got a wx.Toolbar and I'd like to make the buttons larger. I've searched and can't seem to find any concrete documentation on how to do this.</p>
<p>I'm also wondering how well this will translate across platforms; what will happen to the buttons and icons on OSX?</p>
| 2 | 2009-01-14T22:57:53Z | 446,014 | <p>Doesn't the size of the toolbar adapts itself automatically to the size of the bitmap icons? I think if you want a bigger toolbar, you need bigger bitmaps.</p>
| 2 | 2009-01-15T08:28:33Z | [
"python",
"user-interface",
"wxpython",
"wxwidgets",
"toolbar"
] |
How to make a wx Toolbar buttons larger? | 445,037 | <p>I've got a wx.Toolbar and I'd like to make the buttons larger. I've searched and can't seem to find any concrete documentation on how to do this.</p>
<p>I'm also wondering how well this will translate across platforms; what will happen to the buttons and icons on OSX?</p>
| 2 | 2009-01-14T22:57:53Z | 450,702 | <p>It depends on what you want to change: is it the size of the buttons or the size of the icons ?</p>
<p>To change the size of the buttons, use <a href="http://docs.wxwidgets.org/2.6/wx_wxtoolbar.html#wxtoolbarsettoolbitmapsize" rel="nofollow">SetToolBitmapSize</a> (24x24 for instance):</p>
<pre><code>toolbar.SetToo... | 5 | 2009-01-16T15:17:29Z | [
"python",
"user-interface",
"wxpython",
"wxwidgets",
"toolbar"
] |
Cleanest way to run/debug python programs in windows | 445,595 | <p>Python for Windows by default comes with IDLE, which is the barest-bones IDE I've ever encountered. For editing files, I'll stick to emacs, thank you very much.</p>
<p>However, I want to run programs in some other shell than the crappy windows command prompt, which can't be widened to more than 80 characters. </p... | 18 | 2009-01-15T04:01:14Z | 445,601 | <p><a href="http://www.wingware.com/" rel="nofollow">Wing IDE</a> is awesome. They also have a free version.</p>
| 2 | 2009-01-15T04:03:37Z | [
"python",
"windows",
"python-idle"
] |
Cleanest way to run/debug python programs in windows | 445,595 | <p>Python for Windows by default comes with IDLE, which is the barest-bones IDE I've ever encountered. For editing files, I'll stick to emacs, thank you very much.</p>
<p>However, I want to run programs in some other shell than the crappy windows command prompt, which can't be widened to more than 80 characters. </p... | 18 | 2009-01-15T04:01:14Z | 445,607 | <blockquote>
<p>However, I want to run programs in
some other shell than the crappy
windows command prompt, which can't be
widened to more than 80 characters.</p>
</blockquote>
<p>Click on the system box (top-left) in the command prompt and click properties. In the layout tab you can set the width and height o... | 2 | 2009-01-15T04:07:12Z | [
"python",
"windows",
"python-idle"
] |
Cleanest way to run/debug python programs in windows | 445,595 | <p>Python for Windows by default comes with IDLE, which is the barest-bones IDE I've ever encountered. For editing files, I'll stick to emacs, thank you very much.</p>
<p>However, I want to run programs in some other shell than the crappy windows command prompt, which can't be widened to more than 80 characters. </p... | 18 | 2009-01-15T04:01:14Z | 445,618 | <p>You can easily widen the Windows console by doing the following:</p>
<ul>
<li>click the icon for the console window in the upper right</li>
<li>select <strong>Properties</strong> from the menu</li>
<li>click the <strong>Layout</strong> tab</li>
<li>change the <strong>Window Size</strong> > Width to 140</li>
</ul>
... | 8 | 2009-01-15T04:14:05Z | [
"python",
"windows",
"python-idle"
] |
Cleanest way to run/debug python programs in windows | 445,595 | <p>Python for Windows by default comes with IDLE, which is the barest-bones IDE I've ever encountered. For editing files, I'll stick to emacs, thank you very much.</p>
<p>However, I want to run programs in some other shell than the crappy windows command prompt, which can't be widened to more than 80 characters. </p... | 18 | 2009-01-15T04:01:14Z | 445,626 | <p>I edit my Python programs in <a href="http://www.editplus.com/" rel="nofollow">EditPlus</a>. I've configured a user tool that allows me to run my program and have its output appear in a frame below my editor window. My configuration will even let you double click on an exception lines in the output to jump directly ... | 1 | 2009-01-15T04:22:29Z | [
"python",
"windows",
"python-idle"
] |
Cleanest way to run/debug python programs in windows | 445,595 | <p>Python for Windows by default comes with IDLE, which is the barest-bones IDE I've ever encountered. For editing files, I'll stick to emacs, thank you very much.</p>
<p>However, I want to run programs in some other shell than the crappy windows command prompt, which can't be widened to more than 80 characters. </p... | 18 | 2009-01-15T04:01:14Z | 445,682 | <p>For an interactive interpreter, nothing beats <a href="http://ipython.scipy.org/">IPython</a>. It's superb. It's also free and open source. On Windows, you'll want to install the readline library. Instructions for that are on the IPython installation documentation.</p>
<p><a href="http://winpdb.org/">Winpdb</a> is ... | 31 | 2009-01-15T04:49:05Z | [
"python",
"windows",
"python-idle"
] |
Cleanest way to run/debug python programs in windows | 445,595 | <p>Python for Windows by default comes with IDLE, which is the barest-bones IDE I've ever encountered. For editing files, I'll stick to emacs, thank you very much.</p>
<p>However, I want to run programs in some other shell than the crappy windows command prompt, which can't be widened to more than 80 characters. </p... | 18 | 2009-01-15T04:01:14Z | 445,767 | <p>If you ever graduate to vim, you can just run the following command to start the program you're currently editing in an interactive shell:</p>
<pre><code>:!python -i my_script.py
</code></pre>
| 1 | 2009-01-15T05:31:37Z | [
"python",
"windows",
"python-idle"
] |
Cleanest way to run/debug python programs in windows | 445,595 | <p>Python for Windows by default comes with IDLE, which is the barest-bones IDE I've ever encountered. For editing files, I'll stick to emacs, thank you very much.</p>
<p>However, I want to run programs in some other shell than the crappy windows command prompt, which can't be widened to more than 80 characters. </p... | 18 | 2009-01-15T04:01:14Z | 445,810 | <p>I use eclipse with <a href="http://pydev.sourceforge.net/" rel="nofollow">pydev</a>. Eclipse can be sluggish, but I've become attached to integrated svn/cvs, block indent/unindent and run as unittest features. (Also has F5 run)</p>
<p>If your comfortable in emacs though I don't see any reason to make such a major ... | 4 | 2009-01-15T05:56:23Z | [
"python",
"windows",
"python-idle"
] |
Cleanest way to run/debug python programs in windows | 445,595 | <p>Python for Windows by default comes with IDLE, which is the barest-bones IDE I've ever encountered. For editing files, I'll stick to emacs, thank you very much.</p>
<p>However, I want to run programs in some other shell than the crappy windows command prompt, which can't be widened to more than 80 characters. </p... | 18 | 2009-01-15T04:01:14Z | 679,859 | <p>I replaced cmd with Cygwin and Poderosa. May be a little overkill though, if the only problem you have with cmd is that it's a pain to resize.</p>
<p>Although you use Emacs instead of Vim, so I guess you're into overkill... ;-)</p>
| 1 | 2009-03-25T01:03:49Z | [
"python",
"windows",
"python-idle"
] |
GAE - How to live with no joins? | 445,827 | <h2>Example Problem:</h2>
<h3>Entities:</h3>
<ul>
<li>User contains name and a list of friends (User references)</li>
<li>Blog Post contains title, content, date and Writer (User)</li>
</ul>
<h3>Requirement:</h3>
<p>I want a page that displays the title and a link to the blog of the last 10 posts by a user's friend... | 13 | 2009-01-15T06:07:25Z | 446,471 | <p>If you look at how the SQL solution you provided will be executed, it will go basically like this:</p>
<ol>
<li>Fetch a list of friends for the current user</li>
<li>For each user in the list, start an index scan over recent posts</li>
<li>Merge-join all the scans from step 2, stopping when you've retrieved enough ... | 13 | 2009-01-15T11:58:10Z | [
"python",
"google-app-engine",
"join",
"gae-datastore"
] |
GAE - How to live with no joins? | 445,827 | <h2>Example Problem:</h2>
<h3>Entities:</h3>
<ul>
<li>User contains name and a list of friends (User references)</li>
<li>Blog Post contains title, content, date and Writer (User)</li>
</ul>
<h3>Requirement:</h3>
<p>I want a page that displays the title and a link to the blog of the last 10 posts by a user's friend... | 13 | 2009-01-15T06:07:25Z | 446,477 | <p>"Load user, loop through the list of friends and load their latest blog posts."</p>
<p>That's all a join is -- nested loops. Some kinds of joins are loops with lookups. Most lookups are just loops; some are hashes.</p>
<p>"Finally merge all the blog posts to find the latest 10 blog entries"</p>
<p>That's a ORDE... | 1 | 2009-01-15T11:59:10Z | [
"python",
"google-app-engine",
"join",
"gae-datastore"
] |
GAE - How to live with no joins? | 445,827 | <h2>Example Problem:</h2>
<h3>Entities:</h3>
<ul>
<li>User contains name and a list of friends (User references)</li>
<li>Blog Post contains title, content, date and Writer (User)</li>
</ul>
<h3>Requirement:</h3>
<p>I want a page that displays the title and a link to the blog of the last 10 posts by a user's friend... | 13 | 2009-01-15T06:07:25Z | 1,043,333 | <p>This topic is covered in a Google io talk:
<a href="http://code.google.com/events/io/sessions/BuildingScalableComplexApps.html" rel="nofollow">http://code.google.com/events/io/sessions/BuildingScalableComplexApps.html</a></p>
<p>Basically the Google team suggest using list properties and what they call relational i... | 7 | 2009-06-25T11:06:54Z | [
"python",
"google-app-engine",
"join",
"gae-datastore"
] |
GAE - How to live with no joins? | 445,827 | <h2>Example Problem:</h2>
<h3>Entities:</h3>
<ul>
<li>User contains name and a list of friends (User references)</li>
<li>Blog Post contains title, content, date and Writer (User)</li>
</ul>
<h3>Requirement:</h3>
<p>I want a page that displays the title and a link to the blog of the last 10 posts by a user's friend... | 13 | 2009-01-15T06:07:25Z | 1,786,644 | <p>Here is an example in python gleamed from <a href="http://pubsub-test.appspot.com/" rel="nofollow">http://pubsub-test.appspot.com/</a>:</p>
<p>Anyone have one for java? Thanks.</p>
<pre><code>from google.appengine.ext import webapp
from google.appengine.ext import db
class Message(db.Model):
body = db.TextProp... | 0 | 2009-11-23T22:54:57Z | [
"python",
"google-app-engine",
"join",
"gae-datastore"
] |
retrieving XMLHttpRequest parameters in python | 445,942 | <p>Client-side code submits an object (in the POST request body) or query string (if using GET method) via ajax request to a python cgi script. Please note that the object/query string parameters are <strong>not</strong> coming from a</p>
<pre><code><form> or <isindex>.
</code></pre>
<p>How can I retrieve... | 3 | 2009-01-15T07:38:42Z | 445,999 | <p>You use the cgi.FieldStorage class. Example CGI script:</p>
<pre><code>#! /usr/bin/python
import cgi
from os import environ
import cgitb
cgitb.enable()
print "Content-type: text/plain"
print
print "REQUEST_METHOD:", environ["REQUEST_METHOD"]
print "Values:"
f = cgi.FieldStorage()
for k in f.keys():
print "%s:... | 5 | 2009-01-15T08:19:29Z | [
"python",
"ajax",
"cgi"
] |
retrieving XMLHttpRequest parameters in python | 445,942 | <p>Client-side code submits an object (in the POST request body) or query string (if using GET method) via ajax request to a python cgi script. Please note that the object/query string parameters are <strong>not</strong> coming from a</p>
<pre><code><form> or <isindex>.
</code></pre>
<p>How can I retrieve... | 3 | 2009-01-15T07:38:42Z | 446,983 | <p>codeape already answered on this. Just for the record, please understand that how the HTTP request is emitted is totally orthogonal - what the server get is an HTTP request, period.</p>
| 0 | 2009-01-15T14:40:54Z | [
"python",
"ajax",
"cgi"
] |
retrieving XMLHttpRequest parameters in python | 445,942 | <p>Client-side code submits an object (in the POST request body) or query string (if using GET method) via ajax request to a python cgi script. Please note that the object/query string parameters are <strong>not</strong> coming from a</p>
<pre><code><form> or <isindex>.
</code></pre>
<p>How can I retrieve... | 3 | 2009-01-15T07:38:42Z | 447,998 | <p><em>@codeape</em> , <em>@bruno desthuilliers</em>:
<p>
Indeed, cgi.FieldStorage() retrieves the parameters. The output I was getting earlier was apparently due to my passing the parameters as a string (JSON.stringify() object) in the body of the request -- rather than as key-value pairs.<br>
Thanks</p>
| 0 | 2009-01-15T18:59:49Z | [
"python",
"ajax",
"cgi"
] |
Is there an easy way to send SCSI passthrough on OSX using native python | 445,980 | <p>On Windows I am able to sent SCSI passthrough to devices using win32file.DeviceIOControl(..), on UN*X I can do it using fnctl.ioctl(...).</p>
<p>I have been searching for something equivalent in OSX that would allow me to send the IOCTL commands using only native python.</p>
<p>I would to send commands to hard dri... | 2 | 2009-01-15T08:06:12Z | 535,300 | <p>I saw <a href="http://wagerlabs.com/blog/2008/02/04/writing-a-mac-osx-usb-device-driver-that-implements-scsi-pass-through/" rel="nofollow">this blog post</a> recently talking about using SCSI passthrough under OS X. Looks like it isn't as easy as Windows or Unix</p>
| 1 | 2009-02-11T03:19:33Z | [
"python",
"osx"
] |
Django: how do you serve media / stylesheets and link to them within templates | 446,026 | <p>Variations of this question have been asked, but I'm still unable to get my stylesheets to load correctly when my templates are rendered.</p>
<p>I'm attempting to serve static media from the Django process during development - which is strongly discouraged in production, I'm aware. I'll post my configuration and my... | 41 | 2009-01-15T08:35:50Z | 446,116 | <p>I've got a couple of ideas, I don't know which one of them is working for me :)</p>
<blockquote>
<p>Make sure to use a trailing slash, and to have this be different from the MEDIA_URL setting (since the same URL cannot be mapped onto two different sets of files).</p>
</blockquote>
<p>That's from <a href="http://... | 1 | 2009-01-15T09:15:37Z | [
"python",
"css",
"django",
"django-templates",
"media"
] |
Django: how do you serve media / stylesheets and link to them within templates | 446,026 | <p>Variations of this question have been asked, but I'm still unable to get my stylesheets to load correctly when my templates are rendered.</p>
<p>I'm attempting to serve static media from the Django process during development - which is strongly discouraged in production, I'm aware. I'll post my configuration and my... | 41 | 2009-01-15T08:35:50Z | 446,138 | <p>I just use absolute naming. Unless you're running the site in a deep path (or even if you are), I'd drop the <code>..</code> and go for something like:</p>
<pre><code><link rel="stylesheet" type="text/css" href="/media/styles.css">
</code></pre>
| 2 | 2009-01-15T09:27:23Z | [
"python",
"css",
"django",
"django-templates",
"media"
] |
Django: how do you serve media / stylesheets and link to them within templates | 446,026 | <p>Variations of this question have been asked, but I'm still unable to get my stylesheets to load correctly when my templates are rendered.</p>
<p>I'm attempting to serve static media from the Django process during development - which is strongly discouraged in production, I'm aware. I'll post my configuration and my... | 41 | 2009-01-15T08:35:50Z | 447,934 | <p>I usually make my own Template simple tag because Django isn't giving CSS/JavaScript files. Apache does it so my media url is usually <a href="http://static.mysite.com" rel="nofollow">http://static.mysite.com</a>.</p>
<p><strong>yourApp/templatetags/media_url.py:</strong></p>
<pre><code>from django.template import... | 5 | 2009-01-15T18:40:22Z | [
"python",
"css",
"django",
"django-templates",
"media"
] |
Django: how do you serve media / stylesheets and link to them within templates | 446,026 | <p>Variations of this question have been asked, but I'm still unable to get my stylesheets to load correctly when my templates are rendered.</p>
<p>I'm attempting to serve static media from the Django process during development - which is strongly discouraged in production, I'm aware. I'll post my configuration and my... | 41 | 2009-01-15T08:35:50Z | 447,991 | <p>I just had to figure this out myself.</p>
<p>settings.py:</p>
<pre><code>MEDIA_ROOT = 'C:/Server/Projects/project_name/static/'
MEDIA_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/media/'
</code></pre>
<p>urls.py:</p>
<pre><code>from django.conf import settings
...
if settings.DEBUG:
urlpatterns += patterns('',
... | 47 | 2009-01-15T18:56:51Z | [
"python",
"css",
"django",
"django-templates",
"media"
] |
Django: how do you serve media / stylesheets and link to them within templates | 446,026 | <p>Variations of this question have been asked, but I'm still unable to get my stylesheets to load correctly when my templates are rendered.</p>
<p>I'm attempting to serve static media from the Django process during development - which is strongly discouraged in production, I'm aware. I'll post my configuration and my... | 41 | 2009-01-15T08:35:50Z | 461,670 | <p>Just thought I'd chime in quickly. While all the propositions here work just fine, and I do use Ty's example while developing, once you hit production you might want to opt to serve files via a straight Apache, or whichever else server you're using.</p>
<p>What I do is I setup a subdomain once I'm done developing,... | 1 | 2009-01-20T15:04:57Z | [
"python",
"css",
"django",
"django-templates",
"media"
] |
Django: how do you serve media / stylesheets and link to them within templates | 446,026 | <p>Variations of this question have been asked, but I'm still unable to get my stylesheets to load correctly when my templates are rendered.</p>
<p>I'm attempting to serve static media from the Django process during development - which is strongly discouraged in production, I'm aware. I'll post my configuration and my... | 41 | 2009-01-15T08:35:50Z | 479,391 | <p>Django already has a context process for MEDIA_URL, see <a href="http://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-media">Django's documentation</a>.</p>
<p>It should be availbale by default (unless you've customized CONTEXT_PROCESSORS and forgot to add it) in a RequestContext.<... | 10 | 2009-01-26T10:49:00Z | [
"python",
"css",
"django",
"django-templates",
"media"
] |
Django: how do you serve media / stylesheets and link to them within templates | 446,026 | <p>Variations of this question have been asked, but I'm still unable to get my stylesheets to load correctly when my templates are rendered.</p>
<p>I'm attempting to serve static media from the Django process during development - which is strongly discouraged in production, I'm aware. I'll post my configuration and my... | 41 | 2009-01-15T08:35:50Z | 3,451,369 | <p>Another thing to add is that if you have a separate media server on a subdomain/different domain, you can disable cookies for your static media. Saves a little processing and bandwidth.</p>
| 0 | 2010-08-10T16:51:58Z | [
"python",
"css",
"django",
"django-templates",
"media"
] |
How can I check for Python version in a program that uses new language features? | 446,052 | <p>If I have a Python script that requires at least a particular
version of Python, what is the correct way to fail gracefully
when an earlier version of Python is used to launch the script?</p>
<p>How do I get control early enough to issue an error message
and exit?</p>
<p>For example, I have a program that uses the... | 194 | 2009-01-15T08:45:28Z | 446,061 | <p>You can test using <code>eval</code>:</p>
<pre><code>try:
eval("1 if True else 2")
except SyntaxError:
# doesn't have ternary
</code></pre>
<p>Also, <code>with</code> <em>is</em> available in Python 2.5, just add <code>from __future__ import with_statement </code>.</p>
<p>EDIT: to get control early enough, yo... | 88 | 2009-01-15T08:50:17Z | [
"python",
"version"
] |
How can I check for Python version in a program that uses new language features? | 446,052 | <p>If I have a Python script that requires at least a particular
version of Python, what is the correct way to fail gracefully
when an earlier version of Python is used to launch the script?</p>
<p>How do I get control early enough to issue an error message
and exit?</p>
<p>For example, I have a program that uses the... | 194 | 2009-01-15T08:45:28Z | 446,066 | <p>I think the best way is to test for functionality rather than versions. In some cases, this is trivial, not so in others.</p>
<p>eg:</p>
<pre><code>try :
# Do stuff
except : # Features weren't found.
# Do stuff for older versions.
</code></pre>
<p>As long as you're specific in enough in using the try/exce... | 1 | 2009-01-15T08:51:22Z | [
"python",
"version"
] |
How can I check for Python version in a program that uses new language features? | 446,052 | <p>If I have a Python script that requires at least a particular
version of Python, what is the correct way to fail gracefully
when an earlier version of Python is used to launch the script?</p>
<p>How do I get control early enough to issue an error message
and exit?</p>
<p>For example, I have a program that uses the... | 194 | 2009-01-15T08:45:28Z | 446,075 | <p>Try </p>
<pre>
import platform
platform.python_version()
</pre>
<p>Should give you a string like "2.3.1". If this is not exactly waht you want there is a rich set of data available through the "platform" build-in. What you want should be in there somewhere. </p>
| 18 | 2009-01-15T08:55:44Z | [
"python",
"version"
] |
How can I check for Python version in a program that uses new language features? | 446,052 | <p>If I have a Python script that requires at least a particular
version of Python, what is the correct way to fail gracefully
when an earlier version of Python is used to launch the script?</p>
<p>How do I get control early enough to issue an error message
and exit?</p>
<p>For example, I have a program that uses the... | 194 | 2009-01-15T08:45:28Z | 446,136 | <p>Have a wrapper around your program that does the following.</p>
<pre><code>import sys
req_version = (2,5)
cur_version = sys.version_info
if cur_version >= req_version:
import myApp
myApp.run()
else:
print "Your Python interpreter is too old. Please consider upgrading."
</code></pre>
<p>You can also c... | 86 | 2009-01-15T09:26:51Z | [
"python",
"version"
] |
How can I check for Python version in a program that uses new language features? | 446,052 | <p>If I have a Python script that requires at least a particular
version of Python, what is the correct way to fail gracefully
when an earlier version of Python is used to launch the script?</p>
<p>How do I get control early enough to issue an error message
and exit?</p>
<p>For example, I have a program that uses the... | 194 | 2009-01-15T08:45:28Z | 446,181 | <p>Sets became part of the core language in Python 2.4, in order to stay backwards compatible. I did this back then, which will work for you as well:</p>
<pre><code>if sys.version_info < (2, 4):
from sets import Set as set
</code></pre>
| 7 | 2009-01-15T09:43:38Z | [
"python",
"version"
] |
How can I check for Python version in a program that uses new language features? | 446,052 | <p>If I have a Python script that requires at least a particular
version of Python, what is the correct way to fail gracefully
when an earlier version of Python is used to launch the script?</p>
<p>How do I get control early enough to issue an error message
and exit?</p>
<p>For example, I have a program that uses the... | 194 | 2009-01-15T08:45:28Z | 1,424,136 | <p>How about</p>
<pre><code>import sys
def testPyVer(reqver):
if float(sys.version[:3]) >= reqver:
return 1
else:
return 0
#blah blah blah, more code
if testPyVer(3.0) = 1:
#do stuff
else:
#print python requirement, exit statement
</code></pre>
| -1 | 2009-09-14T22:00:06Z | [
"python",
"version"
] |
How can I check for Python version in a program that uses new language features? | 446,052 | <p>If I have a Python script that requires at least a particular
version of Python, what is the correct way to fail gracefully
when an earlier version of Python is used to launch the script?</p>
<p>How do I get control early enough to issue an error message
and exit?</p>
<p>For example, I have a program that uses the... | 194 | 2009-01-15T08:45:28Z | 2,610,308 | <p>The problem is quite simple. You checked if the version was <strong><em>less than</em></strong> 2.4, not less than <strong><em>or equal to</em></strong>. So if the Python version is 2.4, it's not less than 2.4.
What you should have had was:</p>
<pre><code> if sys.version_info **<=** (2, 4):
</code></pre>
<p>... | -3 | 2010-04-09T19:31:02Z | [
"python",
"version"
] |
How can I check for Python version in a program that uses new language features? | 446,052 | <p>If I have a Python script that requires at least a particular
version of Python, what is the correct way to fail gracefully
when an earlier version of Python is used to launch the script?</p>
<p>How do I get control early enough to issue an error message
and exit?</p>
<p>For example, I have a program that uses the... | 194 | 2009-01-15T08:45:28Z | 3,132,402 | <p>Probably the best way to do do this version comparison is to use the <code>sys.hexversion</code>. This is important because comparing version tuples will not give you the desired result in all python versions.</p>
<pre><code>import sys
if sys.hexversion < 0x02060000:
print "yep!"
else:
print "oops!"
</co... | 21 | 2010-06-28T12:38:59Z | [
"python",
"version"
] |
How can I check for Python version in a program that uses new language features? | 446,052 | <p>If I have a Python script that requires at least a particular
version of Python, what is the correct way to fail gracefully
when an earlier version of Python is used to launch the script?</p>
<p>How do I get control early enough to issue an error message
and exit?</p>
<p>For example, I have a program that uses the... | 194 | 2009-01-15T08:45:28Z | 7,396,173 | <p>As noted above, syntax errors occur at compile time, not at run time. While Python is an "interpreted language", Python code is not actually directly interpreted; it's compiled to byte code, which is then interpreted. There is a compile step that happens when a module is imported (if there is no already-compiled v... | 2 | 2011-09-13T02:27:02Z | [
"python",
"version"
] |
How can I check for Python version in a program that uses new language features? | 446,052 | <p>If I have a Python script that requires at least a particular
version of Python, what is the correct way to fail gracefully
when an earlier version of Python is used to launch the script?</p>
<p>How do I get control early enough to issue an error message
and exit?</p>
<p>For example, I have a program that uses the... | 194 | 2009-01-15T08:45:28Z | 7,642,536 | <p>Although the question is:
How do I get control early enough to issue an error message and exit?</p>
<p>The question that I answer is:
How do I get control early enough to issue an error message before starting the app?</p>
<p>I can answer it a lot differently then the other posts.
Seems answers so far are trying t... | 7 | 2011-10-04T01:52:20Z | [
"python",
"version"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.