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 |
|---|---|---|---|---|---|---|---|---|---|
Python sort parallel arrays in place? | 2,222,769 | <p>Is there an easy (meaning without rolling one's own sorting function) way to sort parallel lists <strong>without unnecessary copying</strong> in Python? For example:</p>
<pre><code>foo = range(5)
bar = range(5, 0, -1)
parallelSort(bar, foo)
print foo # [4,3,2,1,0]
print bar # [1,2,3,4,5]
</code></pre>
<p>I've see... | 6 | 2010-02-08T15:49:29Z | 2,222,996 | <p>Is there an easy way? Yes. Use zip.</p>
<p>Is there an "easy way that doesn't use a zip variant"? No.</p>
<p>If you wanted to elaborate on why you object to using zip, that would be helpful. Either you're copying objects, in which case Python will copy by reference, or you're copying something so lightweight into ... | 3 | 2010-02-08T16:18:10Z | [
"python",
"algorithm",
"sorting"
] |
Python sort parallel arrays in place? | 2,222,769 | <p>Is there an easy (meaning without rolling one's own sorting function) way to sort parallel lists <strong>without unnecessary copying</strong> in Python? For example:</p>
<pre><code>foo = range(5)
bar = range(5, 0, -1)
parallelSort(bar, foo)
print foo # [4,3,2,1,0]
print bar # [1,2,3,4,5]
</code></pre>
<p>I've see... | 6 | 2010-02-08T15:49:29Z | 2,223,257 | <p>Any solution I can imagine short of introducing a sort from scratch uses indices, or a dict, or something else that really is not apt to save you memory. In any event, using <code>zip</code> will only increase memory usage by a constant factor, so it is worth making sure this is really a problem before a solution. <... | 0 | 2010-02-08T16:52:36Z | [
"python",
"algorithm",
"sorting"
] |
Python sort parallel arrays in place? | 2,222,769 | <p>Is there an easy (meaning without rolling one's own sorting function) way to sort parallel lists <strong>without unnecessary copying</strong> in Python? For example:</p>
<pre><code>foo = range(5)
bar = range(5, 0, -1)
parallelSort(bar, foo)
print foo # [4,3,2,1,0]
print bar # [1,2,3,4,5]
</code></pre>
<p>I've see... | 6 | 2010-02-08T15:49:29Z | 2,223,828 | <p>Here's an easy way:</p>
<pre><code>perm = sorted(xrange(len(foo)), key=lambda x:foo[x])
</code></pre>
<p>This generates a list of permutations - the value in perm[i] is the index of the ith smallest value in foo. Then, you can access both lists in order:</p>
<pre><code>for p in perm:
print "%s: %s" % (foo[p], b... | 6 | 2010-02-08T18:19:04Z | [
"python",
"algorithm",
"sorting"
] |
Python: making your own statements | 2,222,843 | <p>Is there a way to define new statements like <code>def</code>, <code>with</code>, <code>for</code>,.. of my own in python. Of course, I don't mean to override the existing statements.. Only create some of my own.</p>
<p>If so, how do I do it? Can you point me to good docs on the subject?</p>
| 2 | 2010-02-08T15:58:51Z | 2,222,867 | <p>No, you cannot add new syntax within a Python program. The only way to alter the language is to edit and recompile the grammar file and supporting C code, to obtain a new altered interpreter, compiler and runtime.</p>
| 7 | 2010-02-08T16:01:37Z | [
"python"
] |
Python: making your own statements | 2,222,843 | <p>Is there a way to define new statements like <code>def</code>, <code>with</code>, <code>for</code>,.. of my own in python. Of course, I don't mean to override the existing statements.. Only create some of my own.</p>
<p>If so, how do I do it? Can you point me to good docs on the subject?</p>
| 2 | 2010-02-08T15:58:51Z | 2,222,909 | <p>You can't (re)define language keywords without rewriting a compiler/interpreter/etc. What you could do perhaps is write a something like a DSL (domain-specific language) and something that translates your keyword statements into proper python statements, which might be an easier route.</p>
| 3 | 2010-02-08T16:05:24Z | [
"python"
] |
Python: making your own statements | 2,222,843 | <p>Is there a way to define new statements like <code>def</code>, <code>with</code>, <code>for</code>,.. of my own in python. Of course, I don't mean to override the existing statements.. Only create some of my own.</p>
<p>If so, how do I do it? Can you point me to good docs on the subject?</p>
| 2 | 2010-02-08T15:58:51Z | 2,222,969 | <p>While you can't modify the syntax of Python itself (without recompiling as Alex has mentioned), you can use metaprogramming techniques. Below is a link to a presentation on creating a DSL in Python.</p>
<p><a href="http://blog.brianbeck.com/post/53538107/python-dsl-i" rel="nofollow">http://blog.brianbeck.com/post/5... | 2 | 2010-02-08T16:13:34Z | [
"python"
] |
Python: making your own statements | 2,222,843 | <p>Is there a way to define new statements like <code>def</code>, <code>with</code>, <code>for</code>,.. of my own in python. Of course, I don't mean to override the existing statements.. Only create some of my own.</p>
<p>If so, how do I do it? Can you point me to good docs on the subject?</p>
| 2 | 2010-02-08T15:58:51Z | 2,222,987 | <p><a href="http://www.renpy.org/" rel="nofollow">Ren'Py</a> is an example of an extension for Python that allows custom statements by implementing its own parser and compiler.</p>
| 1 | 2010-02-08T16:17:21Z | [
"python"
] |
Python: making your own statements | 2,222,843 | <p>Is there a way to define new statements like <code>def</code>, <code>with</code>, <code>for</code>,.. of my own in python. Of course, I don't mean to override the existing statements.. Only create some of my own.</p>
<p>If so, how do I do it? Can you point me to good docs on the subject?</p>
| 2 | 2010-02-08T15:58:51Z | 2,223,039 | <p>There are programming languages that let you do this (Tcl, for example), but Python isn't one of those languages. </p>
| 0 | 2010-02-08T16:24:03Z | [
"python"
] |
Python dictionary instead of switch/case | 2,222,859 | <p>I've recently learned that python doesn't have the switch/case statement. I've been reading about using dictionaries in its stead, like this for example:</p>
<pre><code>values = {
value1: do_some_stuff1,
value2: do_some_stuff2,
valueN: do_some_stuffN,
}
values.get(var, do_default_stuff)()
</code><... | 2 | 2010-02-08T16:00:31Z | 2,222,900 | <p>In that case you would use an if/then/else. You cannot do this with a switch, either. </p>
<p>The idea of a switch statement is that you have a value V that you test for identity against N possible outcomes. You can do this with an if-construct - however that would take O(N) runtime on average. The switch gives you... | 3 | 2010-02-08T16:04:39Z | [
"python",
"dictionary",
"switch-statement"
] |
Python dictionary instead of switch/case | 2,222,859 | <p>I've recently learned that python doesn't have the switch/case statement. I've been reading about using dictionaries in its stead, like this for example:</p>
<pre><code>values = {
value1: do_some_stuff1,
value2: do_some_stuff2,
valueN: do_some_stuffN,
}
values.get(var, do_default_stuff)()
</code><... | 2 | 2010-02-08T16:00:31Z | 2,222,922 | <p>Whilst the dictionary approach works well for single values, if you want ranges, <code>if ... else if ... else if</code> is probably the simplest approach.</p>
<p>If you're looking for a single value this a good match to a dictionary - since this is what dictionaries are for - but if you're looking for a range it d... | 4 | 2010-02-08T16:07:23Z | [
"python",
"dictionary",
"switch-statement"
] |
Python dictionary instead of switch/case | 2,222,859 | <p>I've recently learned that python doesn't have the switch/case statement. I've been reading about using dictionaries in its stead, like this for example:</p>
<pre><code>values = {
value1: do_some_stuff1,
value2: do_some_stuff2,
valueN: do_some_stuffN,
}
values.get(var, do_default_stuff)()
</code><... | 2 | 2010-02-08T16:00:31Z | 2,222,958 | <p>A dictionary is the wrong structure for this. The <a href="http://docs.python.org/library/bisect.html#examples"><code>bisect</code> examples</a> show an example of this sort of range test.</p>
| 10 | 2010-02-08T16:11:31Z | [
"python",
"dictionary",
"switch-statement"
] |
Python dictionary instead of switch/case | 2,222,859 | <p>I've recently learned that python doesn't have the switch/case statement. I've been reading about using dictionaries in its stead, like this for example:</p>
<pre><code>values = {
value1: do_some_stuff1,
value2: do_some_stuff2,
valueN: do_some_stuffN,
}
values.get(var, do_default_stuff)()
</code><... | 2 | 2010-02-08T16:00:31Z | 2,222,978 | <p>I don't know of any practicable solution. If you want to go with the <em>guess what it does</em> approach though you could do something like this:</p>
<pre><code>obsure_switch = {
lambda x: 1<x<6 : some_function,
...
}
[action() for condition,action in obscure_switch.iteritems() if condition(var)]
... | 0 | 2010-02-08T16:14:20Z | [
"python",
"dictionary",
"switch-statement"
] |
Python dictionary instead of switch/case | 2,222,859 | <p>I've recently learned that python doesn't have the switch/case statement. I've been reading about using dictionaries in its stead, like this for example:</p>
<pre><code>values = {
value1: do_some_stuff1,
value2: do_some_stuff2,
valueN: do_some_stuffN,
}
values.get(var, do_default_stuff)()
</code><... | 2 | 2010-02-08T16:00:31Z | 2,223,412 | <p><code>dict</code> is not for doing this (nor is switch!). </p>
<p>A couple posters have suggested a dict with containment functions, but this is not the solution you want at all. It is O(n) (like an if statement), it doesn't really work (because you could have overlapping conditions), is unpredictable (because you ... | 2 | 2010-02-08T17:13:12Z | [
"python",
"dictionary",
"switch-statement"
] |
Python dictionary instead of switch/case | 2,222,859 | <p>I've recently learned that python doesn't have the switch/case statement. I've been reading about using dictionaries in its stead, like this for example:</p>
<pre><code>values = {
value1: do_some_stuff1,
value2: do_some_stuff2,
valueN: do_some_stuffN,
}
values.get(var, do_default_stuff)()
</code><... | 2 | 2010-02-08T16:00:31Z | 2,230,227 | <p>Finally figured out what to do!</p>
<p>So instead of using a bunch of elif statements I did this:</p>
<pre><code>range=[10,100]
options='abc'
def func(val)
choose=str(options[bisect(range,val)])
exec choose+"()"
def a():
do_stuff
def b():
do_other_stuff
def c():
do_other_other stuff
</... | -2 | 2010-02-09T15:36:23Z | [
"python",
"dictionary",
"switch-statement"
] |
Using Zimbra SOAP API in Python | 2,222,947 | <p>I'm trying to use the Zimbra SOAP API from Python to programmatically modify & cleanup my contacts but I'm having trouble getting started.</p>
<p>What I have so far is:</p>
<pre><code>from SOAPpy import SOAPProxy
url = 'https://zimbra/service/soap'
auth = {"account": "xxxxx", "password": "xxxxx"}
zimbra = SOA... | 1 | 2010-02-08T16:10:24Z | 26,950,840 | <p>I'd like to nod in the direction of <a href="https://github.com/Zimbra-Community/python-zimbra" rel="nofollow">Python-Zimbra</a>, a python library for Zimbra, which does all that for you.</p>
| 1 | 2014-11-15T21:18:32Z | [
"python",
"soap",
"zimbra"
] |
Using Zimbra SOAP API in Python | 2,222,947 | <p>I'm trying to use the Zimbra SOAP API from Python to programmatically modify & cleanup my contacts but I'm having trouble getting started.</p>
<p>What I have so far is:</p>
<pre><code>from SOAPpy import SOAPProxy
url = 'https://zimbra/service/soap'
auth = {"account": "xxxxx", "password": "xxxxx"}
zimbra = SOA... | 1 | 2010-02-08T16:10:24Z | 32,987,926 | <p>There is also an higher level, and pythonic library: <a href="https://github.com/oasiswork/zimsoap/" rel="nofollow">zimsoap</a>.</p>
<p>Using raw SOAP or <em><a href="https://github.com/Zimbra-Community/python-zimbra" rel="nofollow">python-zimbra</a></em> or <em>zimsoap</em> depends realy on what level of flexibili... | 1 | 2015-10-07T08:56:29Z | [
"python",
"soap",
"zimbra"
] |
Lazy evaluation in Python? Between modules? | 2,223,025 | <p>I'm not sure if something like this is even possible in Python, but if it is it'd be really useful (at least to me in this instance). </p>
<p>I have a test framework in which I want to keep the test configuration separate from the test commands. This is useful because it allows you to mix and match configurations/... | 2 | 2010-02-08T16:22:04Z | 2,223,610 | <p>I hate to answer my own question, but after some more thought, I came up with a potential solution (though I'd love to hear other ideas).</p>
<p>Suppose we have a module mod1:</p>
<pre><code>def myfunc(z):
return z
</code></pre>
<p>and a module mod2:</p>
<pre><code>x = lambda mod: mod.myfunc
</code></pre>
<... | 0 | 2010-02-08T17:42:01Z | [
"python",
"testing",
"lazy-evaluation"
] |
Lazy evaluation in Python? Between modules? | 2,223,025 | <p>I'm not sure if something like this is even possible in Python, but if it is it'd be really useful (at least to me in this instance). </p>
<p>I have a test framework in which I want to keep the test configuration separate from the test commands. This is useful because it allows you to mix and match configurations/... | 2 | 2010-02-08T16:22:04Z | 2,224,370 | <p>Python is dynamically typed, so this is nothing fancy:</p>
<p>configMod.py:</p>
<pre>
##### this is configMod.py #####
modTestArg1 = "Brian"
def runTest(testMod, *args, **kwargs):
testMod.doTest(*args, **kwargs)
</pre>
<p>testMod.py:</p>
<pre>
##### this is testMod.py #####
def doTest(name, address, city="S... | 1 | 2010-02-08T19:44:47Z | [
"python",
"testing",
"lazy-evaluation"
] |
cx_Freeze ImportError: cannot import name | 2,223,128 | <p>I'm trying create an executable for Windows for a GUI application in tkinter using the ttk module. I made an exe with cx_freeze, but when I run the app in the console it gives me the following error:</p>
<pre><code> D:\My Dropbox\python\SAR Calculator\src\dist_tk>
Traceback (most recent call last):
File "C... | 5 | 2010-02-08T16:37:02Z | 2,223,193 | <p>Looks like cx_freeze doesn't realize it should include the <code>tkinter._fix</code> module, which is conditionally imported by <code>tkinter/__init__.py</code>. You can tell it to include that module explicitly with the <code>--include-modules</code> command-line argument, or the <code>includes</code> keyword argum... | 5 | 2010-02-08T16:44:42Z | [
"python",
"python-3.x",
"tkinter",
"exe",
"cx-freeze"
] |
How to execute a function asynchronously every 60 seconds in Python? | 2,223,157 | <p>I want to execute a function every 60 seconds on Python but I don't want to be blocked meanwhile.</p>
<p>How can I do it asynchronously?</p>
<pre><code>import threading
import time
def f():
print("hello world")
threading.Timer(3, f).start()
if __name__ == '__main__':
f()
time.sleep(20)
</code... | 32 | 2010-02-08T16:40:18Z | 2,223,178 | <p>Why dont you create a dedicated thread, in which you put a simple sleeping loop:</p>
<pre><code>#!/usr/bin/env python
import time
while True:
# Your code here
time.sleep(60)
</code></pre>
| 0 | 2010-02-08T16:42:52Z | [
"python",
"function",
"asynchronous",
"call"
] |
How to execute a function asynchronously every 60 seconds in Python? | 2,223,157 | <p>I want to execute a function every 60 seconds on Python but I don't want to be blocked meanwhile.</p>
<p>How can I do it asynchronously?</p>
<pre><code>import threading
import time
def f():
print("hello world")
threading.Timer(3, f).start()
if __name__ == '__main__':
f()
time.sleep(20)
</code... | 32 | 2010-02-08T16:40:18Z | 2,223,182 | <p>You could try the threading.Timer class: <a href="http://docs.python.org/library/threading.html#timer-objects">http://docs.python.org/library/threading.html#timer-objects</a>.</p>
<pre><code>import threading
def f():
# do something here ...
# call f() again in 60 seconds
threading.Timer(60, f).start()
... | 54 | 2010-02-08T16:43:17Z | [
"python",
"function",
"asynchronous",
"call"
] |
How to execute a function asynchronously every 60 seconds in Python? | 2,223,157 | <p>I want to execute a function every 60 seconds on Python but I don't want to be blocked meanwhile.</p>
<p>How can I do it asynchronously?</p>
<pre><code>import threading
import time
def f():
print("hello world")
threading.Timer(3, f).start()
if __name__ == '__main__':
f()
time.sleep(20)
</code... | 32 | 2010-02-08T16:40:18Z | 2,223,191 | <p>The simplest way is to create a background thread that runs something every 60 seconds. A trivial implementation is:</p>
<pre><code>class BackgroundTimer(Thread):
def run(self):
while 1:
Time.sleep(60)
# do something
# ... SNIP ...
# Inside your main thread
# ... SNIP ...
timer = Back... | 0 | 2010-02-08T16:44:12Z | [
"python",
"function",
"asynchronous",
"call"
] |
How to execute a function asynchronously every 60 seconds in Python? | 2,223,157 | <p>I want to execute a function every 60 seconds on Python but I don't want to be blocked meanwhile.</p>
<p>How can I do it asynchronously?</p>
<pre><code>import threading
import time
def f():
print("hello world")
threading.Timer(3, f).start()
if __name__ == '__main__':
f()
time.sleep(20)
</code... | 32 | 2010-02-08T16:40:18Z | 2,223,251 | <p>It depends on what you actually want to do in the mean time. Threads are the most general and least preferred way of doing it; you should be aware of the issues with threading when you use it: not all (non-Python) code allows access from multiple threads simultaneously, communication between threads should be done u... | 2 | 2010-02-08T16:51:45Z | [
"python",
"function",
"asynchronous",
"call"
] |
How to execute a function asynchronously every 60 seconds in Python? | 2,223,157 | <p>I want to execute a function every 60 seconds on Python but I don't want to be blocked meanwhile.</p>
<p>How can I do it asynchronously?</p>
<pre><code>import threading
import time
def f():
print("hello world")
threading.Timer(3, f).start()
if __name__ == '__main__':
f()
time.sleep(20)
</code... | 32 | 2010-02-08T16:40:18Z | 18,057,965 | <p>I googled around and found the Python <a href="http://circuitsframework.com" rel="nofollow">circuits</a> Framework, which makes it possible to wait<br>
for a particular event. </p>
<p>The <code>.callEvent(self, event, *channels)</code> method of circuits contains a fire and suspend-until-response functionality, th... | 2 | 2013-08-05T12:18:21Z | [
"python",
"function",
"asynchronous",
"call"
] |
How to execute a function asynchronously every 60 seconds in Python? | 2,223,157 | <p>I want to execute a function every 60 seconds on Python but I don't want to be blocked meanwhile.</p>
<p>How can I do it asynchronously?</p>
<pre><code>import threading
import time
def f():
print("hello world")
threading.Timer(3, f).start()
if __name__ == '__main__':
f()
time.sleep(20)
</code... | 32 | 2010-02-08T16:40:18Z | 31,172,304 | <p>If you want to invoke the method "on the clock" (e.g. every hour <em>on the hour</em>), you can integrate the following idea with whichever threading mechanism you choose:</p>
<pre><code>import time
def wait(n):
'''Wait until the next increment of n seconds'''
x = time.time()
time.sleep(n-(x%n))
pr... | 1 | 2015-07-01T21:49:25Z | [
"python",
"function",
"asynchronous",
"call"
] |
A class subclass of itself. Why mutual subclassing is forbidden? | 2,223,300 | <p>Complex question I assume, but studying OWL opened a new perspective to live, the universe and everything. I'm going philosophical here.</p>
<p>I am trying to achieve a class C which is subclass of B which in turn is subclass of C. Just for fun, you know...</p>
<p>So here it is</p>
<pre><code>>>> class A... | 4 | 2010-02-08T16:57:22Z | 2,223,331 | <p>I think the answer is "When you construct class C ... it must create instance of class B .. which must create instance of class C ... and so on" This will never end. This is forbidden in most languages (in fact i don't know other case).
You can only create an object with a 'reference' to other object that can be ini... | 1 | 2010-02-08T17:01:30Z | [
"python",
"class",
"design",
"owl"
] |
A class subclass of itself. Why mutual subclassing is forbidden? | 2,223,300 | <p>Complex question I assume, but studying OWL opened a new perspective to live, the universe and everything. I'm going philosophical here.</p>
<p>I am trying to achieve a class C which is subclass of B which in turn is subclass of C. Just for fun, you know...</p>
<p>So here it is</p>
<pre><code>>>> class A... | 4 | 2010-02-08T16:57:22Z | 2,223,343 | <p>Python doesn't allow it because there is no sensible way to do it. You could invent arbitrary rules about how to handle such a case (and perhaps some languages do), but since there is no actual gain in doing so, Python refuses to guess. Classes are required to have a stable, predictable method resolution order for a... | 9 | 2010-02-08T17:03:21Z | [
"python",
"class",
"design",
"owl"
] |
A class subclass of itself. Why mutual subclassing is forbidden? | 2,223,300 | <p>Complex question I assume, but studying OWL opened a new perspective to live, the universe and everything. I'm going philosophical here.</p>
<p>I am trying to achieve a class C which is subclass of B which in turn is subclass of C. Just for fun, you know...</p>
<p>So here it is</p>
<pre><code>>>> class A... | 4 | 2010-02-08T16:57:22Z | 2,223,360 | <p>I'm sure someone can up with an example where this makes sense. However, I guess this restriction is easier and not less powerful.</p>
<p>Eg, Let's say class A holds fields a and b. Class C holds b and c. Then the view on things from C would be: A.a, C.b, C.c and the view from A would be: A.a, A.b, C.c. </p>
<p>Ju... | 0 | 2010-02-08T17:05:51Z | [
"python",
"class",
"design",
"owl"
] |
A class subclass of itself. Why mutual subclassing is forbidden? | 2,223,300 | <p>Complex question I assume, but studying OWL opened a new perspective to live, the universe and everything. I'm going philosophical here.</p>
<p>I am trying to achieve a class C which is subclass of B which in turn is subclass of C. Just for fun, you know...</p>
<p>So here it is</p>
<pre><code>>>> class A... | 4 | 2010-02-08T16:57:22Z | 2,223,382 | <p>The MRO scheme implemented in Python (as of 2.3) forbids cyclic subclassing. Valid MRO's are guaranteed to satisfy "local precedence" and "monotonicity". Cyclic subclassing would break monotonicity. </p>
<p>This issue is discussed in the section entitled <a href="http://www.python.org/download/releases/2.3/mro/" re... | 2 | 2010-02-08T17:08:18Z | [
"python",
"class",
"design",
"owl"
] |
A class subclass of itself. Why mutual subclassing is forbidden? | 2,223,300 | <p>Complex question I assume, but studying OWL opened a new perspective to live, the universe and everything. I'm going philosophical here.</p>
<p>I am trying to achieve a class C which is subclass of B which in turn is subclass of C. Just for fun, you know...</p>
<p>So here it is</p>
<pre><code>>>> class A... | 4 | 2010-02-08T16:57:22Z | 2,223,772 | <p>Part of this "disconnect" is because OWL describes an open world ontology. An Ontology has little or nothing to do with a program, other than a program can manipulate an ontology. </p>
<p>Trying to relate OWL concepts to programming languages is like trying to relate A Pianist and A Piano Sonata. </p>
<p>The so... | 2 | 2010-02-08T18:10:09Z | [
"python",
"class",
"design",
"owl"
] |
A class subclass of itself. Why mutual subclassing is forbidden? | 2,223,300 | <p>Complex question I assume, but studying OWL opened a new perspective to live, the universe and everything. I'm going philosophical here.</p>
<p>I am trying to achieve a class C which is subclass of B which in turn is subclass of C. Just for fun, you know...</p>
<p>So here it is</p>
<pre><code>>>> class A... | 4 | 2010-02-08T16:57:22Z | 2,224,818 | <p>For a semantic reasoner, if A is a subclass of B, and B is a subclass of A, then the classes can be considered equivalent. They are not the "same", but from a reasoning perspective, if I can reason an individual is (or is not) a member of the class A, I can reason the individual is (or is not) a member of the class ... | 1 | 2010-02-08T20:56:20Z | [
"python",
"class",
"design",
"owl"
] |
Multiple ModelAdmins/views for same model in Django admin | 2,223,375 | <p>How can I create more than one ModelAdmin for the same model, each customised differently and linked to different URLs?</p>
<p>Let's say I have a Django model called Posts. By default, the admin view of this model will list all Post objects.</p>
<p>I know I can customise the list of objects displayed on the page i... | 94 | 2010-02-08T17:07:35Z | 2,224,211 | <p>just use a list_filter or date_hierarchy.</p>
<pre><code>date_hierarchy = 'pub_date'
list_filter = ['pub_date',]
</code></pre>
| 1 | 2010-02-08T19:19:05Z | [
"python",
"django",
"django-admin"
] |
Multiple ModelAdmins/views for same model in Django admin | 2,223,375 | <p>How can I create more than one ModelAdmin for the same model, each customised differently and linked to different URLs?</p>
<p>Let's say I have a Django model called Posts. By default, the admin view of this model will list all Post objects.</p>
<p>I know I can customise the list of objects displayed on the page i... | 94 | 2010-02-08T17:07:35Z | 2,228,821 | <p>I've found one way to achieve what I want, by using proxy models to get around the fact that each model may be registered only once.</p>
<pre><code>class PostAdmin(admin.ModelAdmin):
list_display = ('title', 'pubdate','user')
class MyPosts(Post):
class Meta:
proxy = True
class MyPostAdmin(PostAdmi... | 171 | 2010-02-09T11:59:57Z | [
"python",
"django",
"django-admin"
] |
Multiple ModelAdmins/views for same model in Django admin | 2,223,375 | <p>How can I create more than one ModelAdmin for the same model, each customised differently and linked to different URLs?</p>
<p>Let's say I have a Django model called Posts. By default, the admin view of this model will list all Post objects.</p>
<p>I know I can customise the list of objects displayed on the page i... | 94 | 2010-02-08T17:07:35Z | 18,745,241 | <p>Paul Stone answer is absolutely great! Just to add, for Django 1.4.5 I needed to inherit my custom class from <code>admin.ModelAdmin</code></p>
<pre><code>class MyPostAdmin(admin.ModelAdmin):
def queryset(self, request):
return self.model.objects.filter(id=1)
</code></pre>
| 1 | 2013-09-11T15:25:12Z | [
"python",
"django",
"django-admin"
] |
Is ActiveMQ's failover mechanism supported by C# (openwire) & python (stomp) clients? | 2,223,460 | <p>I'd like to use ActiveMQ to connect python service with C# clients.
Is there a way to specify failover connection in C# (openwire) and python (Stomp)?</p>
<p>The ActiveMQ will be configured <a href="http://activemq.apache.org/shared-file-system-master-slave.html" rel="nofollow">Shared File System Master Slave.</a><... | 4 | 2010-02-08T17:21:25Z | 2,246,789 | <p>C# client supports failover see: <a href="http://issues.apache.org/activemq/browse/AMQNET-26" rel="nofollow">http://issues.apache.org/activemq/browse/AMQNET-26</a>.
Python client probably doesn't support it.</p>
| 2 | 2010-02-11T18:41:51Z | [
"c#",
"python",
"activemq",
"stomp",
"nms"
] |
Design pattern for ongoing survey anayisis | 2,223,576 | <p>I'm doing an ongoing survey, every quarter. We get people to sign up (where they give extensive demographic info). </p>
<p>Then we get them to answer six short questions with 5 possible values much worse, worse, same, better, much better. </p>
<p>Of course over time we will not get the same participants,, some wil... | 1 | 2010-02-08T17:38:10Z | 2,223,816 | <p>This is a Data Warehouse. Small, but a data warehouse.</p>
<p>You have a <strong>Star Schema</strong>.</p>
<p>You have Facts:</p>
<ul>
<li>response values are the measures</li>
</ul>
<p>You have Dimensions:</p>
<ul>
<li><p>time period. This has many attributes (year, quarter, month, day, week, etc.) This dim... | 1 | 2010-02-08T18:16:36Z | [
"python",
"design-patterns",
"statistics",
"matrix",
"survey"
] |
Design pattern for ongoing survey anayisis | 2,223,576 | <p>I'm doing an ongoing survey, every quarter. We get people to sign up (where they give extensive demographic info). </p>
<p>Then we get them to answer six short questions with 5 possible values much worse, worse, same, better, much better. </p>
<p>Of course over time we will not get the same participants,, some wil... | 1 | 2010-02-08T17:38:10Z | 2,224,074 | <p>On the analysis, if your six questions have been posed in a way that would lead you to believe the answers will be correlated, consider conducting a factor analysis on the raw scores first. Often comparing the factors across regions or customer type has more statistical power than comparing across questions alone.... | 0 | 2010-02-08T18:56:57Z | [
"python",
"design-patterns",
"statistics",
"matrix",
"survey"
] |
Design pattern for ongoing survey anayisis | 2,223,576 | <p>I'm doing an ongoing survey, every quarter. We get people to sign up (where they give extensive demographic info). </p>
<p>Then we get them to answer six short questions with 5 possible values much worse, worse, same, better, much better. </p>
<p>Of course over time we will not get the same participants,, some wil... | 1 | 2010-02-08T17:38:10Z | 2,225,365 | <p>Regarding the survey analysis portion of your question, I would strongly recommend looking at <a href="http://cran.fhcrc.org/web/packages/survey/index.html" rel="nofollow">the survey package</a> in <a href="http://www.r-project.org" rel="nofollow"><strong>R</strong></a> (which includes a number of useful vignettes, ... | 2 | 2010-02-08T22:28:14Z | [
"python",
"design-patterns",
"statistics",
"matrix",
"survey"
] |
Stopping a thread in python | 2,223,654 | <p>I am creating a thread in my Python app with <code>thread.start_new_thread</code>.</p>
<p>How do I stop it if it hasn't finished in three seconds time?</p>
| 1 | 2010-02-08T17:49:26Z | 2,223,674 | <p>You cannot. Threads can't be killed from outside. The only thing you can do is add a way to ask the thread to exit. Obviously you won't be able to do this if the thread is blocked in some systemcall.</p>
| 1 | 2010-02-08T17:52:19Z | [
"python",
"multithreading"
] |
Stopping a thread in python | 2,223,654 | <p>I am creating a thread in my Python app with <code>thread.start_new_thread</code>.</p>
<p>How do I stop it if it hasn't finished in three seconds time?</p>
| 1 | 2010-02-08T17:49:26Z | 2,223,724 | <p>You can't do that directly. Anyway aborting a thread is not good practice - rather think about using synchronization mechanisms that let you abort the thread in a "soft" way.</p>
<p>But <a href="http://docs.python.org/library/threading.html#threading.Thread.daemon" rel="nofollow">daemonic threads</a> will automatic... | 2 | 2010-02-08T18:01:50Z | [
"python",
"multithreading"
] |
Stopping a thread in python | 2,223,654 | <p>I am creating a thread in my Python app with <code>thread.start_new_thread</code>.</p>
<p>How do I stop it if it hasn't finished in three seconds time?</p>
| 1 | 2010-02-08T17:49:26Z | 2,223,854 | <p>If you really need to do this (e.g. the thread calls code that may hang forever) then consider rewriting your code to spawn a process with the multiprocessing module. You can then kill the process with the Process.terminate() method. You will need 2.6 or later for this, of course.</p>
| 1 | 2010-02-08T18:23:45Z | [
"python",
"multithreading"
] |
Stopping a thread in python | 2,223,654 | <p>I am creating a thread in my Python app with <code>thread.start_new_thread</code>.</p>
<p>How do I stop it if it hasn't finished in three seconds time?</p>
| 1 | 2010-02-08T17:49:26Z | 2,223,883 | <p>As noted in a <a href="http://stackoverflow.com/questions/323972/is-there-any-way-to-kill-a-thread-in-python" title="Is there any way to kill a Thread in Python?">related question</a>, you might be able to raise an exception through <code>ctypes.pythonapi</code>, but not while it's waiting on a system call.</p>
| 1 | 2010-02-08T18:26:36Z | [
"python",
"multithreading"
] |
Online identity verification solution | 2,223,790 | <p>I am building a Python web application and we will need a user identity verification solution... something to verify the users identity during account registration.</p>
<p>I was wondering if anyone had any experience in integrating such a solution. What vendors/products out there have worked well with you? Any tips... | 4 | 2010-02-08T18:12:02Z | 2,223,896 | <p>You should have a look at WS-Trust.
A implementation of that is Windows Identity Foundation. But I'm sure You'll find more.</p>
| 0 | 2010-02-08T18:28:23Z | [
"python",
"identity",
"verification"
] |
Online identity verification solution | 2,223,790 | <p>I am building a Python web application and we will need a user identity verification solution... something to verify the users identity during account registration.</p>
<p>I was wondering if anyone had any experience in integrating such a solution. What vendors/products out there have worked well with you? Any tips... | 4 | 2010-02-08T18:12:02Z | 2,224,273 | <p>There are many different ways to implement a verification system, the concept is quite simple but actually building can be a hassle, especially if you are doing it from scratch. </p>
<p>The best way to approach this is to find a framework that handles the aspect of verification. Turbogears and Pylons are both capab... | 1 | 2010-02-08T19:31:25Z | [
"python",
"identity",
"verification"
] |
Online identity verification solution | 2,223,790 | <p>I am building a Python web application and we will need a user identity verification solution... something to verify the users identity during account registration.</p>
<p>I was wondering if anyone had any experience in integrating such a solution. What vendors/products out there have worked well with you? Any tips... | 4 | 2010-02-08T18:12:02Z | 2,225,965 | <p>We've found <a href="https://rpxnow.com/" rel="nofollow">RPX</a> easy both for the developer and for users.</p>
| 0 | 2010-02-09T00:41:47Z | [
"python",
"identity",
"verification"
] |
Tkinter Canvas Does Not Display | 2,223,985 | <p>I'm attempting to learn some Python and Tkinter. The sample code below is intended to put two windows on the screen, a few buttons, and a Canvas with an image in it and some lines drawn on it.</p>
<p>The windows and buttons appear just fine, however I'm not seeing either the canvas image or canvas lines. I'd appr... | 3 | 2010-02-08T18:43:09Z | 2,224,065 | <p>You need parenthesis when calling pack on the canvas object. Otherwise, you're just referring to the function object, not calling it. </p>
<p>For example:</p>
<pre><code>canvas.pack()
</code></pre>
<p>Another example:</p>
<pre><code>>>>def hello():
... print "hello world"
... return
</code></pre>... | 2 | 2010-02-08T18:55:24Z | [
"python",
"tkinter",
"tkinter-canvas"
] |
Tkinter Canvas Does Not Display | 2,223,985 | <p>I'm attempting to learn some Python and Tkinter. The sample code below is intended to put two windows on the screen, a few buttons, and a Canvas with an image in it and some lines drawn on it.</p>
<p>The windows and buttons appear just fine, however I'm not seeing either the canvas image or canvas lines. I'd appr... | 3 | 2010-02-08T18:43:09Z | 4,037,060 | <p>I solved this problem:</p>
<pre><code>self.photo = ImageTk.PhotoImage(image)
self.item = canvas.create_image(0, 0, image=self.photo)
</code></pre>
<p>A reference to the ImageTk instance must be stored somewhere, or when your <code>App.__init__()</code> method returns, it will be garbage collected, and the canvas w... | 5 | 2010-10-27T19:45:18Z | [
"python",
"tkinter",
"tkinter-canvas"
] |
IPython demo mode | 2,224,082 | <p>I'm trying to use the IPython <a href="http://ipython.scipy.org/doc/stable/html/api/generated/IPython.demo.html" rel="nofollow">demo</a> mode. I created a file called <code>test.py</code> containing:</p>
<pre><code>print 1
print 2
print 3
</code></pre>
<p>and then launched IPython and did the following:</p>
<pre>... | 2 | 2010-02-08T18:59:21Z | 2,224,218 | <p>There seems to be a bug in IPython. In demo.py in <code>LineDemo.reload</code>, the line that says:</p>
<pre><code>src_b = [l for l in self.fobj.readline() if l.strip()]
</code></pre>
<p>should say:</p>
<pre><code>src_b = [l for l in self.fobj.readlines() if l.strip()]
</code></pre>
<p>Curren... | 2 | 2010-02-08T19:20:10Z | [
"python",
"ipython",
"demo"
] |
IPython demo mode | 2,224,082 | <p>I'm trying to use the IPython <a href="http://ipython.scipy.org/doc/stable/html/api/generated/IPython.demo.html" rel="nofollow">demo</a> mode. I created a file called <code>test.py</code> containing:</p>
<pre><code>print 1
print 2
print 3
</code></pre>
<p>and then launched IPython and did the following:</p>
<pre>... | 2 | 2010-02-08T18:59:21Z | 2,224,366 | <p>It works ok in IPython 0.9.1<br>
Which version do you have?</p>
<pre><code>In [1]: from IPython.demo import LineDemo
In [2]: d = LineDemo('test.py')
In [3]: d()
********************* <test.py> block # 0 (2 remaining) *********************
print 1
********************************** output: ******************... | 0 | 2010-02-08T19:43:56Z | [
"python",
"ipython",
"demo"
] |
RSS Feed aggregator using Google App Engine - Python | 2,224,219 | <p>I am trying to build a GAE app that processes an RSS feed and stores all the data from the feed into Google Datastore. I use Minidom to extract content from the RSS feed. I also tried using Feedparser and BeautifulSoup but they did not work for me. </p>
<p>My app currently parses the feed and saves it in the Google... | 4 | 2010-02-08T19:20:35Z | 2,224,721 | <p>It shouldn't take anywhere near that long. Here is how you might use the <a href="http://www.feedparser.org/">Universal Feed Parser</a>.</p>
<pre><code># easy_install feedparser
</code></pre>
<p>And an example of using it:</p>
<pre><code>import feedparser
feed = 'http://stackoverflow.com/feeds/tag?tagnames=pytho... | 6 | 2010-02-08T20:43:42Z | [
"python",
"rss",
"feed"
] |
RSS Feed aggregator using Google App Engine - Python | 2,224,219 | <p>I am trying to build a GAE app that processes an RSS feed and stores all the data from the feed into Google Datastore. I use Minidom to extract content from the RSS feed. I also tried using Feedparser and BeautifulSoup but they did not work for me. </p>
<p>My app currently parses the feed and saves it in the Google... | 4 | 2010-02-08T19:20:35Z | 2,253,676 | <p>I found a way to work around this issue, though I am not sure if this is the optimal solution. </p>
<p>Instead of Minidom I have used cElementTree to parse the RSS feed. I process each "item" tag and its children in a seperate task and add these tasks to the task queue.</p>
<p>This has helped me avoid the Deadline... | 1 | 2010-02-12T17:17:40Z | [
"python",
"rss",
"feed"
] |
RSS Feed aggregator using Google App Engine - Python | 2,224,219 | <p>I am trying to build a GAE app that processes an RSS feed and stores all the data from the feed into Google Datastore. I use Minidom to extract content from the RSS feed. I also tried using Feedparser and BeautifulSoup but they did not work for me. </p>
<p>My app currently parses the feed and saves it in the Google... | 4 | 2010-02-08T19:20:35Z | 20,793,982 | <p>I have a GAE RSS reader demo / prototype working using Feedparser - <a href="http://deliciourss.appspot.com/" rel="nofollow">http://deliciourss.appspot.com/</a>. Here's some code -</p>
<p>Fetch your feed.</p>
<pre><code>data = urlfetch.fetch(feedUrl)
</code></pre>
<p>Parse with Feedparser</p>
<pre><code>parsedD... | 0 | 2013-12-27T02:37:11Z | [
"python",
"rss",
"feed"
] |
How to extract signature from function reference in Python? | 2,224,428 | <p>Let's say I have a function in Python like so:</p>
<pre><code>def foo(x): pass
</code></pre>
<p>According to Python, 'foo' alone is a function reference, right?</p>
<pre><code>>>> def foo(x): pass
...
>>> foo
<function foo at 0xb7f3d1b4>
</code></pre>
<p>Is there any way I can examine the... | 3 | 2010-02-08T19:53:49Z | 2,224,454 | <p>You need <a href="http://docs.python.org/3.1/library/inspect.html#inspect.getfullargspec" rel="nofollow"><code>inspect.getfullargspec</code></a> in py3k or <a href="http://docs.python.org/library/inspect.html#inspect.getargspec" rel="nofollow"><code>inspect.getargspec</code></a> in earlier versions.</p>
<pre><code>... | 4 | 2010-02-08T19:57:19Z | [
"python"
] |
python equivalent of GNU 'cat' that shows unique lines | 2,224,554 | <p>Has anyone written the GNU <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?cat" rel="nofollow">cat</a> command in python and would be willing to share? GNU cat actually does quite a bit & I don't really feel like re-inventing the wheel today. Yes, I did do a google search & and after reading <a href="http://... | 3 | 2010-02-08T20:15:16Z | 2,224,625 | <p>That depends which functionalities you want. If you just want to print out a file, you can do</p>
<pre><code>with open('myfile') as f:
for line in f:
print line,
</code></pre>
<p>or to concatenate some files, you could do</p>
<pre><code>filenames = ['file1', 'file2', 'file3']
for filename in filenames... | 2 | 2010-02-08T20:27:40Z | [
"python"
] |
python equivalent of GNU 'cat' that shows unique lines | 2,224,554 | <p>Has anyone written the GNU <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?cat" rel="nofollow">cat</a> command in python and would be willing to share? GNU cat actually does quite a bit & I don't really feel like re-inventing the wheel today. Yes, I did do a google search & and after reading <a href="http://... | 3 | 2010-02-08T20:15:16Z | 2,224,927 | <p>Latest:
Thank's Ned for the fileinput tip! Here's the latest:</p>
<pre><code>#!/usr/bin/python
"""cat the file, but only the unique lines
"""
import fileinput
if __name__ == "__main__":
lines=set()
for line in fileinput.input():
if not line in lines:
print line,
lines.add(... | 3 | 2010-02-08T21:16:23Z | [
"python"
] |
parsing table with BeautifulSoup and write in text file | 2,224,602 | <p>I need data from table in text file (output.txt) in this format:
data1;data2;data3;data4;.....</p>
<p>Celkova podlahova plocha bytu;33m;Vytah;Ano;Nadzemne podlazie;Prizemne podlazie;.....;Forma vlastnictva;Osobne</p>
<p>All in "<strong>one line</strong>", separator is "<strong>;</strong>" (later export in csv-file... | 6 | 2010-02-08T20:23:27Z | 2,226,569 | <p>You are not keeping each record as you read it in. Try this, which stores the records in <code>records</code>:</p>
<pre><code>from BeautifulSoup import BeautifulSoup
import urllib2
import codecs
response = urllib2.urlopen('http://www.reality.sk/zakazka/0747-003578/predaj/1-izb-byt/kosice-mestska-cast-sever-sladkov... | 9 | 2010-02-09T03:32:52Z | [
"python",
"beautifulsoup"
] |
parsing table with BeautifulSoup and write in text file | 2,224,602 | <p>I need data from table in text file (output.txt) in this format:
data1;data2;data3;data4;.....</p>
<p>Celkova podlahova plocha bytu;33m;Vytah;Ano;Nadzemne podlazie;Prizemne podlazie;.....;Forma vlastnictva;Osobne</p>
<p>All in "<strong>one line</strong>", separator is "<strong>;</strong>" (later export in csv-file... | 6 | 2010-02-08T20:23:27Z | 2,226,643 | <p>here's an alternative non BS way, just for your task</p>
<pre><code>store=[] #to store your results
url="""http://www.reality.sk/zakazka/0747-003578/predaj/1-izb-byt/kosice-mestska-cast-sever-sladkovicova-kosice-sever/art-real-1-izb-byt-sladkovicova-ul-kosice-sever"""
page=urllib2.urlopen(url)
data=page.read()
for ... | 0 | 2010-02-09T03:55:56Z | [
"python",
"beautifulsoup"
] |
Convert dict to array in NumPy | 2,224,620 | <p>I'd like to take a dictionary of a dictionary containing floats, indexed by ints and convert it into a numpy.array for use with the numpy library. Currently I'm manually converting the values into two arrays, one for the original indexes and the other for the values. While I've looked at <code>numpy.asarray</code>... | 5 | 2010-02-08T20:26:57Z | 2,224,744 | <p>You can calculate N and M like this</p>
<pre><code>N=max(foo)+1
M=max(max(x) for x in foo.values())+1
fooarray = numpy.zeros((N, M))
for key1, row in foo.iteritems():
for key2, value in row.iteritems():
fooarray[key1, key2] = value
</code></pre>
<p>There are <a href="http://docs.scipy.org/doc/scipy-0.14... | 4 | 2010-02-08T20:48:05Z | [
"python",
"arrays",
"dictionary",
"numpy"
] |
Convert dict to array in NumPy | 2,224,620 | <p>I'd like to take a dictionary of a dictionary containing floats, indexed by ints and convert it into a numpy.array for use with the numpy library. Currently I'm manually converting the values into two arrays, one for the original indexes and the other for the values. While I've looked at <code>numpy.asarray</code>... | 5 | 2010-02-08T20:26:57Z | 2,224,842 | <p>Say you have a NxM array, then I'd do the following:</p>
<pre><code>myarray = numpy.zeros((N, M))
for key1, row in mydict.iteritems():
for key2, value in row.iteritems():
myarray[key1, key2] = value
</code></pre>
| 1 | 2010-02-08T21:00:13Z | [
"python",
"arrays",
"dictionary",
"numpy"
] |
Business days in Python | 2,224,742 | <p>I need to subtract <em>business days</em> from the current date. </p>
<p>I currently have some code which needs always to be running on the most recent business day. So that may be today if we're Monday thru Friday, but if it's Saturday or Sunday then I need to set it back to the Friday before the weekend. I curren... | 28 | 2010-02-08T20:47:33Z | 2,224,837 | <p>There seem to be several options if you're open to installing extra libraries.</p>
<p>This post describes a way of defining workdays with <a href="http://labix.org/python-dateutil">dateutil</a>.</p>
<p><a href="http://coding.derkeiler.com/Archive/Python/comp.lang.python/2004-09/3758.html">http://coding.derkeiler.c... | 12 | 2010-02-08T20:59:38Z | [
"python",
"datetime"
] |
Business days in Python | 2,224,742 | <p>I need to subtract <em>business days</em> from the current date. </p>
<p>I currently have some code which needs always to be running on the most recent business day. So that may be today if we're Monday thru Friday, but if it's Saturday or Sunday then I need to set it back to the Friday before the weekend. I curren... | 28 | 2010-02-08T20:47:33Z | 9,094,217 | <p>Maybe this code could help:</p>
<pre><code>lastBusDay = datetime.datetime.today()
shift = datetime.timedelta(max(1,(lastBusDay.weekday() + 6) % 7 - 3))
lastBusDay = lastBusDay - shift
</code></pre>
<p>The idea is that on Mondays yo have to go back 3 days, on Sundays 2, and 1 in any other day.</p>
<p>The statement... | 5 | 2012-02-01T10:25:01Z | [
"python",
"datetime"
] |
Business days in Python | 2,224,742 | <p>I need to subtract <em>business days</em> from the current date. </p>
<p>I currently have some code which needs always to be running on the most recent business day. So that may be today if we're Monday thru Friday, but if it's Saturday or Sunday then I need to set it back to the Friday before the weekend. I curren... | 28 | 2010-02-08T20:47:33Z | 18,307,534 | <p>Why don't you try something like:</p>
<pre><code>lastBusDay = datetime.datetime.today()
if datetime.date.weekday(lastBusDay) not in range(0,5):
lastBusDay = 5
</code></pre>
| 0 | 2013-08-19T06:23:29Z | [
"python",
"datetime"
] |
Business days in Python | 2,224,742 | <p>I need to subtract <em>business days</em> from the current date. </p>
<p>I currently have some code which needs always to be running on the most recent business day. So that may be today if we're Monday thru Friday, but if it's Saturday or Sunday then I need to set it back to the Friday before the weekend. I curren... | 28 | 2010-02-08T20:47:33Z | 19,036,752 | <p>Use pandas!</p>
<pre><code>import pandas as pd
# BDay is business day, not birthday...
from pandas.tseries.offsets import BDay
# pd.datetime is an alias for datetime.datetime
today = pd.datetime.today()
print today - BDay(4)
</code></pre>
<p>Since today is Thursday, Sept 26, that will give you an output of:</p>
... | 43 | 2013-09-26T19:16:36Z | [
"python",
"datetime"
] |
Business days in Python | 2,224,742 | <p>I need to subtract <em>business days</em> from the current date. </p>
<p>I currently have some code which needs always to be running on the most recent business day. So that may be today if we're Monday thru Friday, but if it's Saturday or Sunday then I need to set it back to the Friday before the weekend. I curren... | 28 | 2010-02-08T20:47:33Z | 23,378,911 | <pre><code> def getNthBusinessDay(startDate, businessDaysInBetween):
currentDate = startDate
daysToAdd = businessDaysInBetween
while daysToAdd > 0:
currentDate += relativedelta(days=1)
day = currentDate.weekday()
if day < 5:
daysToAdd -= 1
return currentDate
<... | 0 | 2014-04-30T02:59:10Z | [
"python",
"datetime"
] |
Business days in Python | 2,224,742 | <p>I need to subtract <em>business days</em> from the current date. </p>
<p>I currently have some code which needs always to be running on the most recent business day. So that may be today if we're Monday thru Friday, but if it's Saturday or Sunday then I need to set it back to the Friday before the weekend. I curren... | 28 | 2010-02-08T20:47:33Z | 24,352,185 | <p><strong>DISCLAMER:</strong> I'm the author...</p>
<p>I wrote a package that does exactly this, business dates calculations. You can use custom week specification and holidays.</p>
<p>I had this exact problem while working with financial data and didn't find any of the available solutions particularly easy, so I wr... | 6 | 2014-06-22T14:21:22Z | [
"python",
"datetime"
] |
Business days in Python | 2,224,742 | <p>I need to subtract <em>business days</em> from the current date. </p>
<p>I currently have some code which needs always to be running on the most recent business day. So that may be today if we're Monday thru Friday, but if it's Saturday or Sunday then I need to set it back to the Friday before the weekend. I curren... | 28 | 2010-02-08T20:47:33Z | 30,412,106 | <p>This will give a generator of working days, of course without holidays, stop is datetime.datetime object. If you need holidays just make additional argument with list of holidays and check with 'IFology' ;-)</p>
<pre><code>def workingdays(stop, start=datetime.date.today()):
while start != stop:
if start... | 1 | 2015-05-23T11:27:41Z | [
"python",
"datetime"
] |
Silverlight databinding with IronPython and Datagrid | 2,224,805 | <p>We've been successfully using clrtype with IronPython 2.6 and
Silverlight for databinding, based on the example provided by Lukás(:</p>
<p><a href="http://gui-at.blogspot.com/2009/11/inotifypropertychanged-and-databinding.html" rel="nofollow">http://gui-at.blogspot.com/2009/11/inotifypropertychanged-and-databindi... | 0 | 2010-02-08T20:54:01Z | 2,228,082 | <p>I don't know anything about IronPython, but I know that you cannot bind to a Color in Silverlight, regardless of the language used. This has caused me many grievances. In Silverlight 3 you can only bind properties on a FrameworkElement, and since GradientStop is a DependencyObject, it will not work. The good news is... | 1 | 2010-02-09T09:46:28Z | [
"python",
"silverlight",
"data-binding",
"datagrid",
"ironpython"
] |
translate by replacing words inside existing text | 2,224,915 | <p>What are common approaches for translating certain words (or expressions) inside a given text, when the text must be reconstructed (with punctuations and everythin.) ?</p>
<p>The translation comes from a lookup table, and covers words, collocations, and emoticons like L33t, CUL8R, :-), etc.</p>
<p>Simple string se... | 1 | 2010-02-08T21:13:10Z | 2,224,939 | <p>The reason your smiley example doesn't work with regex is the \b refers to a word boundary. Since there are no "word" characters in the smiley, there is no word boundary, so your expression doesn't match. You could use lookaheads/lookbehinds to see if you are bounded by spaces, but to check against punctuation cou... | 1 | 2010-02-08T21:19:51Z | [
"python",
"regex",
"language-agnostic",
"string",
"nlp"
] |
translate by replacing words inside existing text | 2,224,915 | <p>What are common approaches for translating certain words (or expressions) inside a given text, when the text must be reconstructed (with punctuations and everythin.) ?</p>
<p>The translation comes from a lookup table, and covers words, collocations, and emoticons like L33t, CUL8R, :-), etc.</p>
<p>Simple string se... | 1 | 2010-02-08T21:13:10Z | 2,224,944 | <p>The problem is not that regexp can't match smileys (which is simply not true :P), but rather how your regular expression for that smiley is made.</p>
<p>The word boundary <code>\b</code> is described as follows in the python documentation:</p>
<blockquote>
<p>Matches the empty string, but only at the beginning o... | 0 | 2010-02-08T21:20:26Z | [
"python",
"regex",
"language-agnostic",
"string",
"nlp"
] |
translate by replacing words inside existing text | 2,224,915 | <p>What are common approaches for translating certain words (or expressions) inside a given text, when the text must be reconstructed (with punctuations and everythin.) ?</p>
<p>The translation comes from a lookup table, and covers words, collocations, and emoticons like L33t, CUL8R, :-), etc.</p>
<p>Simple string se... | 1 | 2010-02-08T21:13:10Z | 2,225,609 | <p>If you're looking for a non-regex solution, then here is my idea. Here are the steps I would use.</p>
<p>Preparation:</p>
<ul>
<li>Create a dictionary linking the words
to be replaced to their replacements.</li>
<li>Create a ternary tree of the words to
be replaced.</li>
</ul>
<p>Searching and replacing:</p>
<ol... | 0 | 2010-02-08T23:12:19Z | [
"python",
"regex",
"language-agnostic",
"string",
"nlp"
] |
translate by replacing words inside existing text | 2,224,915 | <p>What are common approaches for translating certain words (or expressions) inside a given text, when the text must be reconstructed (with punctuations and everythin.) ?</p>
<p>The translation comes from a lookup table, and covers words, collocations, and emoticons like L33t, CUL8R, :-), etc.</p>
<p>Simple string se... | 1 | 2010-02-08T21:13:10Z | 4,573,042 | <p>I had a similar problem with standard emoticons to be replaced with values. <a href="http://en.wikipedia.org/wiki/List_of_emoticons" rel="nofollow">Here</a> is a list of emoticons. I had them in a plain text file (so that I can append/delete to it as and when required) separated by tab like. </p>
<pre><code>:[ ... | 0 | 2011-01-01T02:55:30Z | [
"python",
"regex",
"language-agnostic",
"string",
"nlp"
] |
Is_prime function via regex in python (from perl) | 2,225,027 | <p>I've read <a href="http://www.noulakaz.net/weblog/2007/03/18/a-regular-expression-to-check-for-prime-numbers/" rel="nofollow">this article</a> where the <code>/^1?$|^(11+?)\1+$/</code> Perl regex is used to test if a number is prime or not.</p>
<p>Process: </p>
<pre><code>s = '1' * your_number
</code></pre>
<p>If... | 9 | 2010-02-08T21:35:35Z | 2,225,060 | <p>It works as is (except without the slashes at the edges, which aren't needed in Python):</p>
<pre><code>pattern = r'^1?$|^(11+?)\1+$'
re.match(pattern, '1'*10) #matches
re.match(pattern, '1'*11) #doesn't match
</code></pre>
<p>The only nonstandard regex feature needed here is backreferences (<code>\1</code>)... | 5 | 2010-02-08T21:39:37Z | [
"python",
"regex",
"perl"
] |
Determine the type of a Python object | 2,225,038 | <p>Is there a simple way to determine if a variable is a list, dictionary, or something else? I am getting an object back that may be either type and I need to be able to tell the difference.</p>
| 839 | 2010-02-08T21:37:20Z | 2,225,055 | <p>You can do that using <code>type()</code>:</p>
<pre><code>>>> a = []
>>> type(a)
<type 'list'>
>>> f = ()
>>> type(f)
<type 'tuple'>
</code></pre>
| 105 | 2010-02-08T21:39:17Z | [
"python"
] |
Determine the type of a Python object | 2,225,038 | <p>Is there a simple way to determine if a variable is a list, dictionary, or something else? I am getting an object back that may be either type and I need to be able to tell the difference.</p>
| 839 | 2010-02-08T21:37:20Z | 2,225,066 | <p>To get the type of an object, you can use the built-in <a href="http://docs.python.org/3/library/functions.html#type"><code>type()</code></a> function. Passing an object as the only parameter will return the type object of that object:</p>
<pre><code>>>> type([]) is list
True
>>> type({}) is dict
... | 1,012 | 2010-02-08T21:40:06Z | [
"python"
] |
Determine the type of a Python object | 2,225,038 | <p>Is there a simple way to determine if a variable is a list, dictionary, or something else? I am getting an object back that may be either type and I need to be able to tell the difference.</p>
| 839 | 2010-02-08T21:37:20Z | 2,225,081 | <p>It might be more Pythonic to use a <code>try</code>...<code>except</code> block. That way, if you have a class which quacks like a list, or quacks like a dict, it will behave properly regardless of what its type <em>really</em> is.</p>
<p>To clarify, the preferred method of "telling the difference" between variable... | 31 | 2010-02-08T21:43:51Z | [
"python"
] |
Determine the type of a Python object | 2,225,038 | <p>Is there a simple way to determine if a variable is a list, dictionary, or something else? I am getting an object back that may be either type and I need to be able to tell the difference.</p>
| 839 | 2010-02-08T21:37:20Z | 17,330,925 | <p>On instances of object you also have the:</p>
<pre class="lang-py prettyprint-override"><code>__class__
</code></pre>
<p>attribute. Here is a sample taken from Python 3.3 console</p>
<pre class="lang-py prettyprint-override"><code>>>> str = "str"
>>> str.__class__
<class 'str'>
>>>... | 20 | 2013-06-26T21:38:42Z | [
"python"
] |
Determine the type of a Python object | 2,225,038 | <p>Is there a simple way to determine if a variable is a list, dictionary, or something else? I am getting an object back that may be either type and I need to be able to tell the difference.</p>
| 839 | 2010-02-08T21:37:20Z | 23,974,819 | <p>You can use <code>type()</code> or <code>isinstance()</code>.</p>
<pre><code>>>> type([]) is list
True
</code></pre>
<p>Be warned that you can clobber <code>list</code> or any other type by assigning a variable in the current scope of the same name.</p>
<pre><code>>>> the_d = {}
>>> t =... | 6 | 2014-05-31T21:57:27Z | [
"python"
] |
Determine the type of a Python object | 2,225,038 | <p>Is there a simple way to determine if a variable is a list, dictionary, or something else? I am getting an object back that may be either type and I need to be able to tell the difference.</p>
| 839 | 2010-02-08T21:37:20Z | 37,876,801 | <p>While the questions is pretty old, I stumbled across this while finding out a proper way myself, and I think it still needs clarifying, <strong>at least for Python 2.x</strong> (did not check on Python 3, but since the issue arises with classic classes which are gone on such version, it probably doesn't matter).</p>... | 2 | 2016-06-17T08:35:20Z | [
"python"
] |
Is there a way for me to get detailed formatted information on a Python class? | 2,225,456 | <p>So, I know I can use dir() to get information about class members etc. What I'm looking for is a way to get a nicely formatted report on everything related to a class (the members, docstrings, inheritance hierarchy, etc.).</p>
<p>I want to be able to run this on the command-line so I can explore code and debug bett... | 1 | 2010-02-08T22:43:02Z | 2,225,477 | <p>Try calling <code>help</code> on your class.</p>
| 5 | 2010-02-08T22:47:15Z | [
"python"
] |
Is there a way for me to get detailed formatted information on a Python class? | 2,225,456 | <p>So, I know I can use dir() to get information about class members etc. What I'm looking for is a way to get a nicely formatted report on everything related to a class (the members, docstrings, inheritance hierarchy, etc.).</p>
<p>I want to be able to run this on the command-line so I can explore code and debug bett... | 1 | 2010-02-08T22:43:02Z | 2,225,488 | <p>Try this from the command line:</p>
<pre><code>pydoc modulename
</code></pre>
| 4 | 2010-02-08T22:49:19Z | [
"python"
] |
Is there a way for me to get detailed formatted information on a Python class? | 2,225,456 | <p>So, I know I can use dir() to get information about class members etc. What I'm looking for is a way to get a nicely formatted report on everything related to a class (the members, docstrings, inheritance hierarchy, etc.).</p>
<p>I want to be able to run this on the command-line so I can explore code and debug bett... | 1 | 2010-02-08T22:43:02Z | 2,225,502 | <p>Not sure exactly what you need, but <a href="http://diveintopython.net/power_of_introspection/index.html" rel="nofollow">this chapter</a> from Mark Pilgrim's "Dive into Python" might work.</p>
| 0 | 2010-02-08T22:51:46Z | [
"python"
] |
Is there a way for me to get detailed formatted information on a Python class? | 2,225,456 | <p>So, I know I can use dir() to get information about class members etc. What I'm looking for is a way to get a nicely formatted report on everything related to a class (the members, docstrings, inheritance hierarchy, etc.).</p>
<p>I want to be able to run this on the command-line so I can explore code and debug bett... | 1 | 2010-02-08T22:43:02Z | 2,225,508 | <p>try <a href="http://ipython.scipy.org" rel="nofollow">ipython</a></p>
| 0 | 2010-02-08T22:53:33Z | [
"python"
] |
Is there a way for me to get detailed formatted information on a Python class? | 2,225,456 | <p>So, I know I can use dir() to get information about class members etc. What I'm looking for is a way to get a nicely formatted report on everything related to a class (the members, docstrings, inheritance hierarchy, etc.).</p>
<p>I want to be able to run this on the command-line so I can explore code and debug bett... | 1 | 2010-02-08T22:43:02Z | 2,225,519 | <p>Try the <code>help()</code> facility that is built into the interpreter. E.g.</p>
<pre><code>class X(object):
"""Docstring for an example class."""
def __init__(self):
"""Docstring for X.__init__()."""
pass
def method1(self, x):
"""Docstring for method1()."""
print x
>... | 1 | 2010-02-08T22:55:06Z | [
"python"
] |
Is there a way for me to get detailed formatted information on a Python class? | 2,225,456 | <p>So, I know I can use dir() to get information about class members etc. What I'm looking for is a way to get a nicely formatted report on everything related to a class (the members, docstrings, inheritance hierarchy, etc.).</p>
<p>I want to be able to run this on the command-line so I can explore code and debug bett... | 1 | 2010-02-08T22:43:02Z | 2,225,527 | <p>You want introspection. This is a good article about all that: <a href="http://www.ibm.com/developerworks/library/l-pyint.html" rel="nofollow">http://www.ibm.com/developerworks/library/l-pyint.html</a></p>
<p>On the other hand, for debugging, you might just want to use Eclipse with the Python plugin.</p>
| 0 | 2010-02-08T22:56:51Z | [
"python"
] |
Get a filtered list of files in a directory | 2,225,564 | <p>I am trying to get a list of files in a directory using Python, but I do not want a list of ALL the files.</p>
<p>What I essentially want is the ability to do something like the following but using Python and not executing ls.</p>
<pre><code>ls 145592*.jpg
</code></pre>
<p>If there is no built-in method for this,... | 117 | 2010-02-08T23:02:56Z | 2,225,582 | <p><a href="http://docs.python.org/library/glob.html#glob.glob"><code>glob.glob('145592*.jpg')</code></a></p>
| 159 | 2010-02-08T23:05:18Z | [
"python",
"filesystems",
"wildcard",
"glob",
"directory-listing"
] |
Get a filtered list of files in a directory | 2,225,564 | <p>I am trying to get a list of files in a directory using Python, but I do not want a list of ALL the files.</p>
<p>What I essentially want is the ability to do something like the following but using Python and not executing ls.</p>
<pre><code>ls 145592*.jpg
</code></pre>
<p>If there is no built-in method for this,... | 117 | 2010-02-08T23:02:56Z | 2,225,927 | <p><code>glob.glob()</code> is definitely the way to do it (as per Ignacio). However, if you do need more complicated matching, you can do it with a list comprehension and <code>re.match()</code>, something like so:</p>
<pre><code>files = [f for f in os.listdir('.') if re.match(r'[0-9]+.*\.jpg', f)]
</code></pre>
<p>... | 53 | 2010-02-09T00:27:32Z | [
"python",
"filesystems",
"wildcard",
"glob",
"directory-listing"
] |
Get a filtered list of files in a directory | 2,225,564 | <p>I am trying to get a list of files in a directory using Python, but I do not want a list of ALL the files.</p>
<p>What I essentially want is the ability to do something like the following but using Python and not executing ls.</p>
<pre><code>ls 145592*.jpg
</code></pre>
<p>If there is no built-in method for this,... | 117 | 2010-02-08T23:02:56Z | 2,226,226 | <p>use os.walk to recursively list your files</p>
<pre><code>import os
root = "/home"
pattern = "145992"
alist_filter = ['jpg','bmp','png','gif']
path=os.path.join(root,"mydir_to_scan")
for r,d,f in os.walk(path):
for file in f:
if file[-3:] in alist_filter and pattern in file:
print os.path.... | 6 | 2010-02-09T01:46:50Z | [
"python",
"filesystems",
"wildcard",
"glob",
"directory-listing"
] |
Get a filtered list of files in a directory | 2,225,564 | <p>I am trying to get a list of files in a directory using Python, but I do not want a list of ALL the files.</p>
<p>What I essentially want is the ability to do something like the following but using Python and not executing ls.</p>
<pre><code>ls 145592*.jpg
</code></pre>
<p>If there is no built-in method for this,... | 117 | 2010-02-08T23:02:56Z | 21,096,293 | <p>Keep it simple:</p>
<pre><code>import os
relevant_path = "[path to folder]"
included_extenstions = ['jpg', 'bmp', 'png', 'gif']
file_names = [fn for fn in os.listdir(relevant_path)
if any(fn.endswith(ext) for ext in included_extenstions)]
</code></pre>
<p>I prefer this form of list comprehensions bec... | 18 | 2014-01-13T16:27:48Z | [
"python",
"filesystems",
"wildcard",
"glob",
"directory-listing"
] |
Get a filtered list of files in a directory | 2,225,564 | <p>I am trying to get a list of files in a directory using Python, but I do not want a list of ALL the files.</p>
<p>What I essentially want is the ability to do something like the following but using Python and not executing ls.</p>
<pre><code>ls 145592*.jpg
</code></pre>
<p>If there is no built-in method for this,... | 117 | 2010-02-08T23:02:56Z | 23,943,909 | <p>you might also like a more high-level approach (I have implemented and packaged as <strong>findtools</strong>):</p>
<pre><code>from findtools.find_files import (find_files, Match)
# Recursively find all *.txt files in **/home/**
txt_files_pattern = Match(filetype='f', name='*.txt')
found_files = find_files(path='... | 0 | 2014-05-29T22:13:17Z | [
"python",
"filesystems",
"wildcard",
"glob",
"directory-listing"
] |
Get a filtered list of files in a directory | 2,225,564 | <p>I am trying to get a list of files in a directory using Python, but I do not want a list of ALL the files.</p>
<p>What I essentially want is the ability to do something like the following but using Python and not executing ls.</p>
<pre><code>ls 145592*.jpg
</code></pre>
<p>If there is no built-in method for this,... | 117 | 2010-02-08T23:02:56Z | 35,060,836 | <p>Another option:</p>
<pre class="lang-py prettyprint-override"><code>>>> import os, fnmatch
>>> fnmatch.filter(os.listdir('.'), '*.py')
['manage.py']
</code></pre>
<p><a href="https://docs.python.org/3.4/library/fnmatch.html">https://docs.python.org/3.4/library/fnmatch.html</a></p>
| 5 | 2016-01-28T11:55:54Z | [
"python",
"filesystems",
"wildcard",
"glob",
"directory-listing"
] |
Get a filtered list of files in a directory | 2,225,564 | <p>I am trying to get a list of files in a directory using Python, but I do not want a list of ALL the files.</p>
<p>What I essentially want is the ability to do something like the following but using Python and not executing ls.</p>
<pre><code>ls 145592*.jpg
</code></pre>
<p>If there is no built-in method for this,... | 117 | 2010-02-08T23:02:56Z | 39,748,501 | <p>You can use subprocess.check_ouput() as</p>
<pre><code>import subprocess
list_files = subprocess.check_output("ls 145992*.jpg", shell=True)
</code></pre>
<p>Of course, the string between quotes can be anything you want to execute in the shell, and store the output.</p>
| 0 | 2016-09-28T13:08:40Z | [
"python",
"filesystems",
"wildcard",
"glob",
"directory-listing"
] |
Which version of python opencv should I go for? | 2,225,913 | <p>Having successfully installed opencv 2.0 with python bindings I'm starting to run into trouble and before I go any further I wondered if I should change to another option. As ezod on this <a href="http://stackoverflow.com/questions/1540298/new-pythoninterface-for-opencv">post</a> says:</p>
<p>"As a caveat, as of th... | 7 | 2010-02-09T00:22:42Z | 2,380,610 | <p>I'm using a self-compiled OpenCV 2.0 and it's built-in python binding. Up to now I was missing 2 or 3 functions (e.g. <em>FindFundamentalMat</em>). If you get the source code of OpenCV you find a text file <strong>interfaces/python/api</strong> that defines the parameter and return types for each OpenCV function tha... | 1 | 2010-03-04T15:50:04Z | [
"python",
"opencv"
] |
Which version of python opencv should I go for? | 2,225,913 | <p>Having successfully installed opencv 2.0 with python bindings I'm starting to run into trouble and before I go any further I wondered if I should change to another option. As ezod on this <a href="http://stackoverflow.com/questions/1540298/new-pythoninterface-for-opencv">post</a> says:</p>
<p>"As a caveat, as of th... | 7 | 2010-02-09T00:22:42Z | 3,397,490 | <p>I'd recommend you use <a href="http://opencv.willowgarage.com/documentation/python/index.html" rel="nofollow">the official Python bindings to OpenCV 2.1</a> which as far as I've seen has feature parity with the C++ libraries. Most of them have either a pythonic wrapper, or a direct translation from the C++ version.<... | 0 | 2010-08-03T14:27:56Z | [
"python",
"opencv"
] |
Which version of python opencv should I go for? | 2,225,913 | <p>Having successfully installed opencv 2.0 with python bindings I'm starting to run into trouble and before I go any further I wondered if I should change to another option. As ezod on this <a href="http://stackoverflow.com/questions/1540298/new-pythoninterface-for-opencv">post</a> says:</p>
<p>"As a caveat, as of th... | 7 | 2010-02-09T00:22:42Z | 9,681,257 | <p>A late answer. If you do not have to depend on earlier versions, and want to use OpenCV with Python, choose the latest stable version. Today it is OpenCV 2.3.1.</p>
<p>The major benefit of <strong>OpenCV ⥠2.3 for Python</strong> users: a new <code>cv2</code> module in addition to the old (backwards compatible) <... | 3 | 2012-03-13T09:21:03Z | [
"python",
"opencv"
] |
How can I create stacked line graph with matplotlib? | 2,225,995 | <p>I would like to be able to produce a stacked line graph (similar to the method used <a href="http://www.whitehouse.gov/omb/budget/fy2003/images/bud20c.jpg">here</a>) with Python (preferably using matplotlib, but another library would be fine too). How can I do this?</p>
<p>This similar to the <a href="http://matpl... | 30 | 2010-02-09T00:51:38Z | 2,226,261 | <p>A slightly less hackish way would be to use a line graph in the first place and <code>matplotlib.pyplot.fill_between</code>. To emulate the stacking you have to shift the points up yourself.</p>
<pre><code>x = np.arange(0,4)
y1 = np.array([1,2,4,3])
y2 = np.array([5,2,1,3])
# y2 should go on top, so shift them up
y... | 7 | 2010-02-09T01:56:37Z | [
"python",
"matplotlib"
] |
How can I create stacked line graph with matplotlib? | 2,225,995 | <p>I would like to be able to produce a stacked line graph (similar to the method used <a href="http://www.whitehouse.gov/omb/budget/fy2003/images/bud20c.jpg">here</a>) with Python (preferably using matplotlib, but another library would be fine too). How can I do this?</p>
<p>This similar to the <a href="http://matpl... | 30 | 2010-02-09T00:51:38Z | 2,226,534 | <p>I believe <strong><em>Area Plot</em></strong> is a common term for this type of plot, and in the specific instance recited in the OP, <strong><em>Stacked Area Plot</em></strong>. </p>
<p>Matplotlib does not have an "out-of-the-box" function that combines <em>both</em> the data processing and drawing/rendering steps... | 40 | 2010-02-09T03:20:09Z | [
"python",
"matplotlib"
] |
How can I create stacked line graph with matplotlib? | 2,225,995 | <p>I would like to be able to produce a stacked line graph (similar to the method used <a href="http://www.whitehouse.gov/omb/budget/fy2003/images/bud20c.jpg">here</a>) with Python (preferably using matplotlib, but another library would be fine too). How can I do this?</p>
<p>This similar to the <a href="http://matpl... | 30 | 2010-02-09T00:51:38Z | 21,418,313 | <p>Newer versions of matplotlib contain the function <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.stackplot"><code>plt.stackplot</code></a>, which allow for several different "out-of-the-box" stacked area plots:</p>
<pre><code>import numpy as np
import pylab as plt
X = np.arange(0, 10, 1)
Y =... | 35 | 2014-01-28T22:31:48Z | [
"python",
"matplotlib"
] |
Error message in python-mysql cursor: 1054 unknown column "x" in 'field list' | 2,226,258 | <p>This is my first post! I <em>also</em> just started programming, so please bear with me! </p>
<p>I am trying to load a bunch of .csv files into a database, in order to later perform various reports on the data. I started off by creating a few tables in mysql with matching field names and data types to what will be ... | 5 | 2010-02-09T01:55:52Z | 2,226,296 | <p>You should be using DB-API quoting instead of including the data in the SQL query directly:</p>
<pre><code>sql = """INSERT INTO temporary_load
(domain_name, session_count, search_count, click_count,
revenue, revenue_per_min, cost_per_click, traffic_date)
VALUES (%s, %d, %d, %d, %d, %d, %d, %s)"""
args =... | 1 | 2010-02-09T02:05:31Z | [
"python",
"mysql",
"mysql-error-1054"
] |
Error message in python-mysql cursor: 1054 unknown column "x" in 'field list' | 2,226,258 | <p>This is my first post! I <em>also</em> just started programming, so please bear with me! </p>
<p>I am trying to load a bunch of .csv files into a database, in order to later perform various reports on the data. I started off by creating a few tables in mysql with matching field names and data types to what will be ... | 5 | 2010-02-09T01:55:52Z | 2,234,500 | <p><a href="http://stackoverflow.com/questions/2226258/error-message-in-python-mysql-cursor-1054-unknown-column-x-in-field-list/2226296#2226296"><strong>Thomas</strong></a> is, as usual, absolutely correct: feel free to let MySQLdb handle the quoting issues.</p>
<p>In addition to that recommendation:</p>
<ol>
<li>The... | 2 | 2010-02-10T04:55:48Z | [
"python",
"mysql",
"mysql-error-1054"
] |
Python vars() global name error | 2,226,386 | <p>I'm having a bit of trouble understanding what's going wrong with the following function:</p>
<pre><code>def ness():
pie='yum'
vars()[pie]=4
print vars()[pie]
print yum
</code></pre>
<p>So When I run that I get this result:</p>
<pre><code>>>> ness()
4
Traceback (most recent call last):
File "<st... | 3 | 2010-02-09T02:38:47Z | 2,226,393 | <p>It's <a href="http://docs.python.org/library/functions.html#vars" rel="nofollow">not safe</a> to modify the dict returned by vars()</p>
<blockquote>
<p>vars([object])¶</p>
<p>Without an argument, act like locals().</p>
<p>With a module, class or class instance object as argument (or
anything else tha... | 1 | 2010-02-09T02:40:07Z | [
"python",
"global"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.