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 |
|---|---|---|---|---|---|---|---|---|---|
Using global variables in a function other than the one that created them | 423,379 | <p>If I create a global variable in one function, how can I use that variable in another function?<br>
Do I need to store the global variable in a local variable of the function which needs its access?</p>
| 1,686 | 2009-01-08T05:45:02Z | 6,664,227 | <p>Python uses a simple heuristic to decide which scope it should load a variable from, between local and global. If a variable name appears on the left hand side of an assignment, but is not declared global, it is assumed to be local. If it does not appear on the left hand side of an assignment, it is assumed to be ... | 50 | 2011-07-12T12:35:08Z | [
"python",
"global-variables",
"scope"
] |
Using global variables in a function other than the one that created them | 423,379 | <p>If I create a global variable in one function, how can I use that variable in another function?<br>
Do I need to store the global variable in a local variable of the function which needs its access?</p>
| 1,686 | 2009-01-08T05:45:02Z | 19,151,605 | <p>Global variables are much more fun when you deal with parallel execution. Here is an example of using a global variable within multiprocessing. We can clearly see that each process works with its own copy of the variable:</p>
<pre><code>import multiprocessing
import time
import os
import sys
import random
def worke... | 14 | 2013-10-03T05:41:16Z | [
"python",
"global-variables",
"scope"
] |
Using global variables in a function other than the one that created them | 423,379 | <p>If I create a global variable in one function, how can I use that variable in another function?<br>
Do I need to store the global variable in a local variable of the function which needs its access?</p>
| 1,686 | 2009-01-08T05:45:02Z | 19,347,254 | <p>As it turns out the answer is always simple.</p>
<p>Here is a small sample module. It is is a way to show it in a main definition:</p>
<pre><code>def five(enterAnumber,sumation):
global helper
helper = enterAnumber + sumation
def isTheNumber():
return helper
</code></pre>
<p>Here is a way to show it... | 8 | 2013-10-13T16:07:41Z | [
"python",
"global-variables",
"scope"
] |
Using global variables in a function other than the one that created them | 423,379 | <p>If I create a global variable in one function, how can I use that variable in another function?<br>
Do I need to store the global variable in a local variable of the function which needs its access?</p>
| 1,686 | 2009-01-08T05:45:02Z | 24,572,187 | <p>In addition to already existing answers and to make this more confusing:</p>
<blockquote>
<p>In Python, variables that are only referenced inside a function are
<strong>implicitly global</strong>. If a variable is assigned a new value anywhere
within the functionâs body, itâs assumed to be a <strong>local... | 21 | 2014-07-04T10:23:56Z | [
"python",
"global-variables",
"scope"
] |
Using global variables in a function other than the one that created them | 423,379 | <p>If I create a global variable in one function, how can I use that variable in another function?<br>
Do I need to store the global variable in a local variable of the function which needs its access?</p>
| 1,686 | 2009-01-08T05:45:02Z | 27,287,648 | <p>What you are saying is to use the method like this:</p>
<pre><code>globvar = 5
def f():
var = globvar
print(var)
f()** #prints 5
</code></pre>
<p>but the better way is to use the global variable like this:<br/></p>
<pre><code>globavar = 5
def f():
global globvar
print(globvar)
f() #prints 5
<... | 8 | 2014-12-04T06:27:43Z | [
"python",
"global-variables",
"scope"
] |
Using global variables in a function other than the one that created them | 423,379 | <p>If I create a global variable in one function, how can I use that variable in another function?<br>
Do I need to store the global variable in a local variable of the function which needs its access?</p>
| 1,686 | 2009-01-08T05:45:02Z | 27,580,376 | <p>You need to reference the global variable in every function you want to use.</p>
<p>As follows:</p>
<pre><code>var = "test"
def printGlobalText():
global var #wWe are telling to explicitly use the global version
var = "global from printGlobalText fun."
print "var from printGlobalText: " + var
def pri... | 8 | 2014-12-20T12:45:26Z | [
"python",
"global-variables",
"scope"
] |
Using global variables in a function other than the one that created them | 423,379 | <p>If I create a global variable in one function, how can I use that variable in another function?<br>
Do I need to store the global variable in a local variable of the function which needs its access?</p>
| 1,686 | 2009-01-08T05:45:02Z | 28,329,600 | <p>Try This :</p>
<pre><code>def x1():
global x
x = 6
def x2():
global x
x = x+1
print x
x = 5
x1()
x2()
</code></pre>
| 4 | 2015-02-04T19:19:54Z | [
"python",
"global-variables",
"scope"
] |
Using global variables in a function other than the one that created them | 423,379 | <p>If I create a global variable in one function, how can I use that variable in another function?<br>
Do I need to store the global variable in a local variable of the function which needs its access?</p>
| 1,686 | 2009-01-08T05:45:02Z | 33,320,055 | <p>following on and as an add on use a file to contain all global variables all declared locally and then 'import as'</p>
<pre><code>file initval.py
Stocksin = 300
Prices = []
File getstocks.py
import initval as iv
Def getmystocks ():
iv.Stocksin = getstockcount ()
Def getmycharts ():
For ic i... | 2 | 2015-10-24T15:46:18Z | [
"python",
"global-variables",
"scope"
] |
Using global variables in a function other than the one that created them | 423,379 | <p>If I create a global variable in one function, how can I use that variable in another function?<br>
Do I need to store the global variable in a local variable of the function which needs its access?</p>
| 1,686 | 2009-01-08T05:45:02Z | 34,559,513 | <blockquote>
<h1>If I create a global variable in one function, how can I use that variable in another function?</h1>
</blockquote>
<p>We can create a global with the following function:</p>
<pre><code>def create_global_variable():
global global_variable # must declare it to be a global first
# modification... | 10 | 2016-01-01T19:55:14Z | [
"python",
"global-variables",
"scope"
] |
Using global variables in a function other than the one that created them | 423,379 | <p>If I create a global variable in one function, how can I use that variable in another function?<br>
Do I need to store the global variable in a local variable of the function which needs its access?</p>
| 1,686 | 2009-01-08T05:45:02Z | 34,664,752 | <p>Writing to explicit elements of a global array does not apparently need the global declaration, though writing to it "wholesale" does have that requirement:</p>
<pre><code>import numpy as np
hostValue = 3.14159
hostArray = np.array([2., 3.])
hostMatrix = np.array([[1.0, 0.0],[ 0.0, 1.0]])
def func1():
global ... | 3 | 2016-01-07T20:41:19Z | [
"python",
"global-variables",
"scope"
] |
Using global variables in a function other than the one that created them | 423,379 | <p>If I create a global variable in one function, how can I use that variable in another function?<br>
Do I need to store the global variable in a local variable of the function which needs its access?</p>
| 1,686 | 2009-01-08T05:45:02Z | 35,831,191 | <p>I've found that when you try to assign a global variable to something else inside a function, it doesn't usually work. As in:</p>
<pre><code>globalVar = 1
def functionname():
global globalVar
globalVar = 18
print globalVar
</code></pre>
<p>What works for me to change it is when I assign it <em>outs... | -4 | 2016-03-06T19:04:21Z | [
"python",
"global-variables",
"scope"
] |
long double returns and ctypes | 423,404 | <p>i have a c function which returns a <code>long double</code>. i'd like to call this function from python using ctypes, and it mostly works. setting <code>so.func.restype = c_longdouble</code> does the trick -- except that python's float type is a <code>c_double</code> so if the returned value is larger than a doub... | 9 | 2009-01-08T06:00:48Z | 423,479 | <p>I'm not sure you can do it without modifying the C code. ctypes seems to have really bad support for <code>long double</code>s - you can't manipulate them like numbers at all, all you can do is convert them back and forth between the native <code>float</code> Python type.</p>
<p>You can't even use a byte array as ... | 1 | 2009-01-08T06:56:41Z | [
"python",
"ctypes"
] |
long double returns and ctypes | 423,404 | <p>i have a c function which returns a <code>long double</code>. i'd like to call this function from python using ctypes, and it mostly works. setting <code>so.func.restype = c_longdouble</code> does the trick -- except that python's float type is a <code>c_double</code> so if the returned value is larger than a doub... | 9 | 2009-01-08T06:00:48Z | 423,491 | <p>If you need high-precision floating point, have a look at GMPY.</p>
<p><a href="http://code.google.com/p/gmpy/" rel="nofollow">GMPY</a> is a C-coded Python extension module that wraps the GMP library to provide to Python code fast multiprecision arithmetic (integer, rational, and float), random number generation, a... | 0 | 2009-01-08T07:08:54Z | [
"python",
"ctypes"
] |
long double returns and ctypes | 423,404 | <p>i have a c function which returns a <code>long double</code>. i'd like to call this function from python using ctypes, and it mostly works. setting <code>so.func.restype = c_longdouble</code> does the trick -- except that python's float type is a <code>c_double</code> so if the returned value is larger than a doub... | 9 | 2009-01-08T06:00:48Z | 28,994,452 | <p>If you have a function return a <em>subclass</em> of <code>c_longdouble</code>, it will return the ctypes wrapped field object rather than converting to a python <code>float</code>. You can then extract the bytes from this (with <code>memcpy</code> into a c_char array, for example) or pass the object to another C fu... | 1 | 2015-03-11T18:21:36Z | [
"python",
"ctypes"
] |
How to save inline formset models in Django? | 423,437 | <p>Formsets have a .save() method, and the <a href="http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-an-inline-formset-in-a-view" rel="nofollow">documentation</a> says to save in views like this:</p>
<pre><code>if request.method == "POST":
formset = BookInlineFormSet(request.POST, request.FILES,... | 3 | 2009-01-08T06:28:41Z | 423,804 | <p>I discovered my problem, and it's embarrassing.</p>
<p>In the parent model form I had <code>exclude = ('...',)</code> in the Meta class, and one of the excluded fields was critical for the relations in the inline_formsets. So, I've removed the excludes and ignoring those fields in the template.</p>
| 4 | 2009-01-08T10:27:55Z | [
"python",
"django",
"django-forms"
] |
Python unittest with expensive setup | 423,483 | <p>My test file is basically:</p>
<pre><code>class Test(unittest.TestCase):
def testOk():
pass
if __name__ == "__main__":
expensiveSetup()
try:
unittest.main()
finally:
cleanUp()
</code></pre>
<p>However, I do wish to run my test through Netbeans testing tools, and to do that ... | 18 | 2009-01-08T07:00:36Z | 423,569 | <p>You can save the state if <code>expensiveSetup()</code> is run or not.</p>
<pre><code>__expensiveSetup_has_run = False
class ExpensiveSetupMixin(unittest.TestCase):
def setUp(self):
global __expensiveSetup_has_run
super(ExpensiveSetupMixin, self).setUp()
if __expensiveSetup_has_run is F... | 2 | 2009-01-08T08:08:44Z | [
"python",
"unit-testing"
] |
Python unittest with expensive setup | 423,483 | <p>My test file is basically:</p>
<pre><code>class Test(unittest.TestCase):
def testOk():
pass
if __name__ == "__main__":
expensiveSetup()
try:
unittest.main()
finally:
cleanUp()
</code></pre>
<p>However, I do wish to run my test through Netbeans testing tools, and to do that ... | 18 | 2009-01-08T07:00:36Z | 423,887 | <p>You can assure <code>setUp</code> and <code>tearDown</code> execute once if you have only one test method, <code>runTest</code>. This method can do whatever else it wants. Just be sure you don't have any methods with names that start with <code>test</code>.</p>
<pre><code>class MyExpensiveTest( unittest.TestCase ... | -2 | 2009-01-08T11:03:35Z | [
"python",
"unit-testing"
] |
Python unittest with expensive setup | 423,483 | <p>My test file is basically:</p>
<pre><code>class Test(unittest.TestCase):
def testOk():
pass
if __name__ == "__main__":
expensiveSetup()
try:
unittest.main()
finally:
cleanUp()
</code></pre>
<p>However, I do wish to run my test through Netbeans testing tools, and to do that ... | 18 | 2009-01-08T07:00:36Z | 424,438 | <p>First of all, what S. Lott said. However!, you do not want to do that. There is a reason setUp and tearDown are wrapped around each test: they help preserve the determinism of testing.</p>
<p>Otherwise, if some test places the system in a bad state, your next tests may fail. Ideally, each of your tests should be in... | 5 | 2009-01-08T14:35:18Z | [
"python",
"unit-testing"
] |
Python unittest with expensive setup | 423,483 | <p>My test file is basically:</p>
<pre><code>class Test(unittest.TestCase):
def testOk():
pass
if __name__ == "__main__":
expensiveSetup()
try:
unittest.main()
finally:
cleanUp()
</code></pre>
<p>However, I do wish to run my test through Netbeans testing tools, and to do that ... | 18 | 2009-01-08T07:00:36Z | 425,483 | <p>If you use Python >= 2.7 (or <a href="http://pypi.python.org/pypi/unittest2">unittest2</a> for Python >= 2.4 & <= 2.6), the best approach would be be to use </p>
<pre><code>def setUpClass(cls):
# ...
setUpClass = classmethod(setUpClass)
</code></pre>
<p>to perform some initialization once for all tests ... | 21 | 2009-01-08T19:12:44Z | [
"python",
"unit-testing"
] |
Python unittest with expensive setup | 423,483 | <p>My test file is basically:</p>
<pre><code>class Test(unittest.TestCase):
def testOk():
pass
if __name__ == "__main__":
expensiveSetup()
try:
unittest.main()
finally:
cleanUp()
</code></pre>
<p>However, I do wish to run my test through Netbeans testing tools, and to do that ... | 18 | 2009-01-08T07:00:36Z | 431,932 | <p>Won't package-level initialization do it for you? From the <a href="https://nose.readthedocs.org/en/latest/writing_tests.html?highlight=setup_package" rel="nofollow">Nose Wiki</a>:</p>
<blockquote>
<p>nose allows tests to be grouped into
test packages. This allows
package-level setup; for instance, if
you n... | 3 | 2009-01-10T23:07:09Z | [
"python",
"unit-testing"
] |
Python unittest with expensive setup | 423,483 | <p>My test file is basically:</p>
<pre><code>class Test(unittest.TestCase):
def testOk():
pass
if __name__ == "__main__":
expensiveSetup()
try:
unittest.main()
finally:
cleanUp()
</code></pre>
<p>However, I do wish to run my test through Netbeans testing tools, and to do that ... | 18 | 2009-01-08T07:00:36Z | 4,577,724 | <p>This is what I do:</p>
<pre><code>class TestSearch(unittest.TestCase):
"""General Search tests for...."""
matcher = None
counter = 0
num_of_tests = None
def setUp(self): # pylint: disable-msg=C0103
"""Only instantiate the matcher once"""
if self.matcher is None:
... | 5 | 2011-01-02T08:31:13Z | [
"python",
"unit-testing"
] |
Python unittest with expensive setup | 423,483 | <p>My test file is basically:</p>
<pre><code>class Test(unittest.TestCase):
def testOk():
pass
if __name__ == "__main__":
expensiveSetup()
try:
unittest.main()
finally:
cleanUp()
</code></pre>
<p>However, I do wish to run my test through Netbeans testing tools, and to do that ... | 18 | 2009-01-08T07:00:36Z | 4,578,214 | <p>I know nothing about Netbeans, but I though I should mention <a href="http://pypi.python.org/pypi/zope.testrunner" rel="nofollow">zope.testrunner</a> and it's support for a nifty thing: Layers. Basically, you do the testsetup in separate classes, and attach those classes to the tests. These classes can inherit from ... | 0 | 2011-01-02T11:43:59Z | [
"python",
"unit-testing"
] |
Python and different Operating Systems | 425,343 | <p>I am about to start a personal project using python and I will be using it on both Linux(Fedora) and Windows(Vista), Although I might as well make it work on a mac while im at it. I have found an API for the GUI that will work on all 3. The reason I am asking is because I have always heard of small differences that ... | 4 | 2009-01-08T18:38:09Z | 425,383 | <p>In general:</p>
<ul>
<li>Be careful with paths. Use os.path wherever possible.</li>
<li>Don't assume that HOME points to the user's home/profile directory.</li>
<li>Avoid using things like unix-domain sockets, fifos, and other POSIX-specific stuff.</li>
</ul>
<p>More specific stuff:</p>
<ul>
<li>If you're using w... | 4 | 2009-01-08T18:49:31Z | [
"python",
"cross-platform"
] |
Python and different Operating Systems | 425,343 | <p>I am about to start a personal project using python and I will be using it on both Linux(Fedora) and Windows(Vista), Although I might as well make it work on a mac while im at it. I have found an API for the GUI that will work on all 3. The reason I am asking is because I have always heard of small differences that ... | 4 | 2009-01-08T18:38:09Z | 425,403 | <ol>
<li><p>You should take care of the Python version you are developing against. Especially, on a Mac, the default version of Python installed with the OS, is rather old (of course, newer versions can be installed)</p></li>
<li><p>Don't use the OS specific libraries</p></li>
<li><p>Take special care of 'special' UI e... | 1 | 2009-01-08T18:55:12Z | [
"python",
"cross-platform"
] |
Python and different Operating Systems | 425,343 | <p>I am about to start a personal project using python and I will be using it on both Linux(Fedora) and Windows(Vista), Although I might as well make it work on a mac while im at it. I have found an API for the GUI that will work on all 3. The reason I am asking is because I have always heard of small differences that ... | 4 | 2009-01-08T18:38:09Z | 425,409 | <p>Some things I've noticed in my cross platform development in Python:</p>
<ul>
<li>OSX doesn't have a tray, so application notifications usually happen right in the dock. So if you're building a background notification service you may need a small amount of platform-specific code.</li>
<li>os.startfile() apparently... | 3 | 2009-01-08T18:56:46Z | [
"python",
"cross-platform"
] |
Python and different Operating Systems | 425,343 | <p>I am about to start a personal project using python and I will be using it on both Linux(Fedora) and Windows(Vista), Although I might as well make it work on a mac while im at it. I have found an API for the GUI that will work on all 3. The reason I am asking is because I have always heard of small differences that ... | 4 | 2009-01-08T18:38:09Z | 425,465 | <p>Some filename problems: This.File and this.file are different files on Linux, but point to the same file on Windows. Troublesome if you manage some file repository and access it from both platforms. Less frequent related problem is that of names like NUL or LPT being files on Windows.</p>
<p>Binary distribution cod... | 0 | 2009-01-08T19:08:40Z | [
"python",
"cross-platform"
] |
Best Way To Determine if a Sequence is in another sequence in Python | 425,604 | <p>This is a generalization of the "string contains substring" problem to (more) arbitrary types.</p>
<p>Given an sequence (such as a list or tuple), what's the best way of determining whether another sequence is inside it? As a bonus, it should return the index of the element where the subsequence starts:</p>
<p>E... | 15 | 2009-01-08T19:46:10Z | 425,622 | <p>Brute force may be fine for small patterns.</p>
<p>For larger ones, look at the <a href="http://en.wikipedia.org/wiki/Aho-Corasick_algorithm" rel="nofollow">Aho-Corasick algorithm</a>.</p>
| 1 | 2009-01-08T19:51:19Z | [
"python",
"algorithm",
"sequence"
] |
Best Way To Determine if a Sequence is in another sequence in Python | 425,604 | <p>This is a generalization of the "string contains substring" problem to (more) arbitrary types.</p>
<p>Given an sequence (such as a list or tuple), what's the best way of determining whether another sequence is inside it? As a bonus, it should return the index of the element where the subsequence starts:</p>
<p>E... | 15 | 2009-01-08T19:46:10Z | 425,677 | <p>Same thing as string matching sir...<a href="http://www.ics.uci.edu/~eppstein/161/960227.html" rel="nofollow">Knuth-Morris-Pratt string matching</a></p>
| 5 | 2009-01-08T20:05:09Z | [
"python",
"algorithm",
"sequence"
] |
Best Way To Determine if a Sequence is in another sequence in Python | 425,604 | <p>This is a generalization of the "string contains substring" problem to (more) arbitrary types.</p>
<p>Given an sequence (such as a list or tuple), what's the best way of determining whether another sequence is inside it? As a bonus, it should return the index of the element where the subsequence starts:</p>
<p>E... | 15 | 2009-01-08T19:46:10Z | 425,764 | <pre><code>>>> def seq_in_seq(subseq, seq):
... while subseq[0] in seq:
... index = seq.index(subseq[0])
... if subseq == seq[index:index + len(subseq)]:
... return index
... else:
... seq = seq[index + 1:]
... else:
... return -1
...
>>>... | 1 | 2009-01-08T20:26:54Z | [
"python",
"algorithm",
"sequence"
] |
Best Way To Determine if a Sequence is in another sequence in Python | 425,604 | <p>This is a generalization of the "string contains substring" problem to (more) arbitrary types.</p>
<p>Given an sequence (such as a list or tuple), what's the best way of determining whether another sequence is inside it? As a bonus, it should return the index of the element where the subsequence starts:</p>
<p>E... | 15 | 2009-01-08T19:46:10Z | 425,825 | <p>I second the Knuth-Morris-Pratt algorithm. By the way, your problem (and the KMP solution) is exactly recipe 5.13 in <a href="http://rads.stackoverflow.com/amzn/click/0596007973">Python Cookbook</a> 2nd edition. You can find the related code at <a href="http://code.activestate.com/recipes/117214/">http://code.active... | 14 | 2009-01-08T20:42:46Z | [
"python",
"algorithm",
"sequence"
] |
Best Way To Determine if a Sequence is in another sequence in Python | 425,604 | <p>This is a generalization of the "string contains substring" problem to (more) arbitrary types.</p>
<p>Given an sequence (such as a list or tuple), what's the best way of determining whether another sequence is inside it? As a bonus, it should return the index of the element where the subsequence starts:</p>
<p>E... | 15 | 2009-01-08T19:46:10Z | 425,838 | <p>Here is another KMP implementation:</p>
<pre><code>from itertools import tee
def seq_in_seq(seq1,seq2):
'''
Return the index where seq1 appears in seq2, or -1 if
seq1 is not in seq2, using the Knuth-Morris-Pratt algorithm
based heavily on code by Neale Pickett <neale@woozle.org>
found a... | 0 | 2009-01-08T20:44:55Z | [
"python",
"algorithm",
"sequence"
] |
Best Way To Determine if a Sequence is in another sequence in Python | 425,604 | <p>This is a generalization of the "string contains substring" problem to (more) arbitrary types.</p>
<p>Given an sequence (such as a list or tuple), what's the best way of determining whether another sequence is inside it? As a bonus, it should return the index of the element where the subsequence starts:</p>
<p>E... | 15 | 2009-01-08T19:46:10Z | 426,168 | <p>Here's a brute-force approach <code>O(n*m)</code> (similar to <a href="http://stackoverflow.com/questions/425604/best-way-to-determine-if-a-sequence-is-in-another-sequence-in-python#425764">@mcella's answer</a>). It might be faster then the Knuth-Morris-Pratt algorithm implementation in pure Python <code>O(n+m)</cod... | 3 | 2009-01-08T21:55:59Z | [
"python",
"algorithm",
"sequence"
] |
Best Way To Determine if a Sequence is in another sequence in Python | 425,604 | <p>This is a generalization of the "string contains substring" problem to (more) arbitrary types.</p>
<p>Given an sequence (such as a list or tuple), what's the best way of determining whether another sequence is inside it? As a bonus, it should return the index of the element where the subsequence starts:</p>
<p>E... | 15 | 2009-01-08T19:46:10Z | 29,424,456 | <p>A simple approach: Convert to strings and rely on string matching.</p>
<p>Example using lists of strings:</p>
<pre><code> >>> f = ["foo", "bar", "baz"]
>>> g = ["foo", "bar"]
>>> ff = str(f).strip("[]")
>>> gg = str(g).strip("[]")
>>> gg in ff
True
</code></pre>
<... | 1 | 2015-04-03T00:07:40Z | [
"python",
"algorithm",
"sequence"
] |
Best Way To Determine if a Sequence is in another sequence in Python | 425,604 | <p>This is a generalization of the "string contains substring" problem to (more) arbitrary types.</p>
<p>Given an sequence (such as a list or tuple), what's the best way of determining whether another sequence is inside it? As a bonus, it should return the index of the element where the subsequence starts:</p>
<p>E... | 15 | 2009-01-08T19:46:10Z | 34,059,337 | <p>Another approach, using sets:</p>
<pre><code>set([5,6])== set([5,6])&set([4,'a',3,5,6])
True
</code></pre>
| -1 | 2015-12-03T06:36:22Z | [
"python",
"algorithm",
"sequence"
] |
Drag button between panels in wxPython | 425,722 | <p>Does anyone know of an example where it is shown how to drag a button from one panel to another in wxPython?</p>
<p>I have created a bitmap button in a panel, and I would like to be able to drag it to a different panel and drop I there. </p>
<p>I haven't found any examples using buttons, just text and files.</p>
... | 1 | 2009-01-08T20:17:05Z | 425,740 | <p>If you want to graphically represent the drag, one good way to do this is to create a borderless Frame that follows the mouse during a drag. You remove the button from your source Frame, temporarily put it in this "drag Frame", and then, when the user drops, add it to your destination Frame.</p>
| 3 | 2009-01-08T20:21:50Z | [
"python",
"drag-and-drop",
"wxpython"
] |
Django on IronPython | 425,990 | <p>I am interested in getting an install of Django running on IronPython, has anyone had any success getting this running with some level of success? </p>
<p>If so can you please tell of your experiences, performance, suggest some tips, resources and gotchas?</p>
| 50 | 2009-01-08T21:16:01Z | 426,257 | <p><a href="http://blogs.msdn.com/dinoviehland/archive/2008/03/17/ironpython-ms-sql-and-pep-249.aspx">Here's a database provider that runs on .NET & that works with Django</a></p>
| 8 | 2009-01-08T22:20:23Z | [
"python",
"django",
"ironpython"
] |
Django on IronPython | 425,990 | <p>I am interested in getting an install of Django running on IronPython, has anyone had any success getting this running with some level of success? </p>
<p>If so can you please tell of your experiences, performance, suggest some tips, resources and gotchas?</p>
| 50 | 2009-01-08T21:16:01Z | 509,424 | <p>This was <a href="http://www.infoq.com/news/2008/03/django-and-ironpython" rel="nofollow">demoed</a> at last year's PyCon (the <a href="http://blogs.msdn.com/dinoviehland/archive/2008/03/17/ironpython-ms-sql-and-pep-249.aspx" rel="nofollow">details</a> are also available). More recently, <a href="http://jdhardy.blo... | 5 | 2009-02-03T23:17:20Z | [
"python",
"django",
"ironpython"
] |
Django on IronPython | 425,990 | <p>I am interested in getting an install of Django running on IronPython, has anyone had any success getting this running with some level of success? </p>
<p>If so can you please tell of your experiences, performance, suggest some tips, resources and gotchas?</p>
| 50 | 2009-01-08T21:16:01Z | 518,317 | <p>Besides the Jeff Hardy blog post on <a href="http://jdhardy.blogspot.com/2008/12/django-ironpython.html">Django + IronPython</a> mentioned by Tony Meyer, it might be useful to also read Jeff's two other posts in the same series on his struggles with IronPython, easy_install and zlib. The first is <a href="http://jdh... | 25 | 2009-02-05T22:40:08Z | [
"python",
"django",
"ironpython"
] |
Django on IronPython | 425,990 | <p>I am interested in getting an install of Django running on IronPython, has anyone had any success getting this running with some level of success? </p>
<p>If so can you please tell of your experiences, performance, suggest some tips, resources and gotchas?</p>
| 50 | 2009-01-08T21:16:01Z | 3,870,431 | <p>I don't think Django is yet working on IronPython, but I'm not saying it cannot be done.</p>
<p><a href="http://bitbucket.org/jdhardy/django-ironpython/overview" rel="nofollow">Django-ironpython</a> project is a work currently underway to run Django on IronPython. The project has reported <a href="http://twitter.co... | 2 | 2010-10-06T07:51:45Z | [
"python",
"django",
"ironpython"
] |
How do I (successfully) decode a encoded password from command line openSSL? | 426,294 | <p>Using PyCrypto (although I've tried this in ObjC with OpenSSL bindings as well) :</p>
<pre><code>from Crypto.Cipher import DES
import base64
obj=DES.new('abcdefgh', DES.MODE_ECB)
plain="Guido van Rossum is a space alien.XXXXXX"
ciph=obj.encrypt(plain)
enc=base64.b64encode(ciph)
#print ciph
print enc
</code></pre>
... | 2 | 2009-01-08T22:30:01Z | 427,344 | <p><code>
echo ESzjTnGMRFnfVOJwQfqtyXOI8yzAatioyufiSdE1dx02McNkZ2IvBg== | openssl enc -nopad -a -des-ecb -K 6162636465666768 -iv 0 -p -d
</code></p>
<p>6162636465666768 is the ASCII "abcdefgh" written out in hexadecimal.</p>
<p>But note that DES in ECB mode is probably not a good way to encode passwords and also is n... | 3 | 2009-01-09T07:41:44Z | [
"python",
"linux",
"bash",
"encryption",
"openssl"
] |
How to use the HTTPPasswordMgrWithDefaultRealm() in Python | 426,298 | <p>I need to write some python ftp code that uses a ftp proxy. The proxy doesn't require authentication but the ftp server I am connecting to does. I have the following code but I am getting a "I/O error(ftp error): 501 USER format: proxy-user:auth-method@destination. Closing connection." error. My code is:</p>
<pre><... | 1 | 2009-01-08T22:32:07Z | 426,331 | <p>I use the following code block which seems similar except i include the protocol in the <code>top_level_url</code> I use (and of course it's http). </p>
<p>You might also try calling <code>install_opener</code> after each <code>build_opener</code> call and then using <code>urllib2.urlopen</code></p>
<pre><code>aut... | 2 | 2009-01-08T22:41:37Z | [
"python"
] |
How to use the HTTPPasswordMgrWithDefaultRealm() in Python | 426,298 | <p>I need to write some python ftp code that uses a ftp proxy. The proxy doesn't require authentication but the ftp server I am connecting to does. I have the following code but I am getting a "I/O error(ftp error): 501 USER format: proxy-user:auth-method@destination. Closing connection." error. My code is:</p>
<pre><... | 1 | 2009-01-08T22:32:07Z | 13,391,859 | <p>I think you need to change this:</p>
<pre><code> opener = urllib2.build_opener(proxy_support )
opener = urllib2.build_opener(handler )
</code></pre>
<p>to this:</p>
<pre><code> opener = urllib2.build_opener([proxy_support, handler])
</code></pre>
<p>That gives you one opener that has both your authenti... | 0 | 2012-11-15T05:09:27Z | [
"python"
] |
How do I mock the Python method OptionParser.error(), which does a sys.exit()? | 426,500 | <p>I'm trying to unit test some code that looks like this:</p>
<pre><code>def main():
parser = optparse.OptionParser(description='This tool is cool', prog='cool-tool')
parser.add_option('--foo', action='store', help='The foo option is self-explanatory')
options, arguments = parser.parse_args()
if not o... | 14 | 2009-01-08T23:37:31Z | 426,624 | <p>Will this work instead of <code>assertEquals</code>?</p>
<pre><code>self.assertRaises(SystemExit, sut.main, 2)
</code></pre>
<p>This should catch the <code>SystemExit</code> exception and prevent the script from terminating.</p>
| 12 | 2009-01-09T00:24:15Z | [
"python",
"unit-testing",
"mocking",
"optparse"
] |
How do I mock the Python method OptionParser.error(), which does a sys.exit()? | 426,500 | <p>I'm trying to unit test some code that looks like this:</p>
<pre><code>def main():
parser = optparse.OptionParser(description='This tool is cool', prog='cool-tool')
parser.add_option('--foo', action='store', help='The foo option is self-explanatory')
options, arguments = parser.parse_args()
if not o... | 14 | 2009-01-08T23:37:31Z | 427,288 | <p>Probably this question contains some new information:</p>
<p><a href="http://stackoverflow.com/questions/309396/java-how-to-test-methods-that-call-system-exit">http://stackoverflow.com/questions/309396/java-how-to-test-methods-that-call-system-exit</a></p>
| 0 | 2009-01-09T07:09:48Z | [
"python",
"unit-testing",
"mocking",
"optparse"
] |
How do I mock the Python method OptionParser.error(), which does a sys.exit()? | 426,500 | <p>I'm trying to unit test some code that looks like this:</p>
<pre><code>def main():
parser = optparse.OptionParser(description='This tool is cool', prog='cool-tool')
parser.add_option('--foo', action='store', help='The foo option is self-explanatory')
options, arguments = parser.parse_args()
if not o... | 14 | 2009-01-08T23:37:31Z | 455,576 | <p>As noted in my updates to my question, I had to modify <a href="http://stackoverflow.com/users/3002/df">dF</a>'s answer to:</p>
<pre><code>self.assertRaises(SystemExit, sut.main)
</code></pre>
<p>...and I came up with a few longer snippet to test for the exit code.</p>
<p>[Note: I accepted my own answer, but I wi... | 1 | 2009-01-18T17:48:48Z | [
"python",
"unit-testing",
"mocking",
"optparse"
] |
How do I mock the Python method OptionParser.error(), which does a sys.exit()? | 426,500 | <p>I'm trying to unit test some code that looks like this:</p>
<pre><code>def main():
parser = optparse.OptionParser(description='This tool is cool', prog='cool-tool')
parser.add_option('--foo', action='store', help='The foo option is self-explanatory')
options, arguments = parser.parse_args()
if not o... | 14 | 2009-01-08T23:37:31Z | 13,688,099 | <p>Add <code>@raises</code> to your test function. I.e:</p>
<pre><code>from nose.tools import raises
@raises(SystemExit)
@patch('optparse.OptionParser')
def test_main_with_missing_p4clientsdir_option(self, mock_optionparser):
# Setup
...
sut.main()
</code></pre>
| 0 | 2012-12-03T17:00:16Z | [
"python",
"unit-testing",
"mocking",
"optparse"
] |
PyObjc vs RubyCocoa for Mac development: Which is more mature? | 426,607 | <p>I've been wanting to have a play with either Ruby or Python while at the same time I've been wanting to do a bit of Cocoa programming.</p>
<p>So I thought the best way to achieve both these goals is to develop something using either a Ruby or Python to Objective-C bridge (PyObjc or RubyCocoa).</p>
<p>I know that ... | 8 | 2009-01-09T00:16:24Z | 426,703 | <p>While you say you "don't have time" to learn technologies independently the fastest route to learning Cocoa will still be to learn it in its native language: Objective-C. Once you understand Objective-C and have gotten over the initial learning curve of the Cocoa frameworks you'll have a much easier time picking up... | 11 | 2009-01-09T01:08:54Z | [
"python",
"ruby",
"cocoa",
"pyobjc",
"ruby-cocoa"
] |
PyObjc vs RubyCocoa for Mac development: Which is more mature? | 426,607 | <p>I've been wanting to have a play with either Ruby or Python while at the same time I've been wanting to do a bit of Cocoa programming.</p>
<p>So I thought the best way to achieve both these goals is to develop something using either a Ruby or Python to Objective-C bridge (PyObjc or RubyCocoa).</p>
<p>I know that ... | 8 | 2009-01-09T00:16:24Z | 426,733 | <p>Both are roughly equal, I'd say. Better in some places, worse in others. But I wouldn't recommend learning Cocoa with either. Like Chris said, Cocoa requires some understanding of Objective-C. I like Ruby better than Objective-C, but I still don't recommend using it to learn Cocoa. Once you have a solid foundation (... | 3 | 2009-01-09T01:25:52Z | [
"python",
"ruby",
"cocoa",
"pyobjc",
"ruby-cocoa"
] |
PyObjc vs RubyCocoa for Mac development: Which is more mature? | 426,607 | <p>I've been wanting to have a play with either Ruby or Python while at the same time I've been wanting to do a bit of Cocoa programming.</p>
<p>So I thought the best way to achieve both these goals is to develop something using either a Ruby or Python to Objective-C bridge (PyObjc or RubyCocoa).</p>
<p>I know that ... | 8 | 2009-01-09T00:16:24Z | 426,883 | <p>Apple seems to be getting behind Ruby scripting for Cocoa but not RubyCocoa. They are hosting and I believe supporting <a href="http://www.macruby.org/trac/wiki/MacRuby" rel="nofollow">MacRuby</a>. I often wonder if MacRuby is Apple's answer to a higher level language for OSX prototyping and full on application de... | 1 | 2009-01-09T02:41:13Z | [
"python",
"ruby",
"cocoa",
"pyobjc",
"ruby-cocoa"
] |
PyObjc vs RubyCocoa for Mac development: Which is more mature? | 426,607 | <p>I've been wanting to have a play with either Ruby or Python while at the same time I've been wanting to do a bit of Cocoa programming.</p>
<p>So I thought the best way to achieve both these goals is to develop something using either a Ruby or Python to Objective-C bridge (PyObjc or RubyCocoa).</p>
<p>I know that ... | 8 | 2009-01-09T00:16:24Z | 429,727 | <p>I would echo Chris' assesment and will expand a bit on why you should learn Objective-C to learn Cocoa. As Chris says, Objective-C is the foundation and native language of Cocoa and many of its paradigms are inextricably linked with that lineage. In particular, selectors and dynamic message resolution and ability to... | 8 | 2009-01-09T21:02:42Z | [
"python",
"ruby",
"cocoa",
"pyobjc",
"ruby-cocoa"
] |
PyObjc vs RubyCocoa for Mac development: Which is more mature? | 426,607 | <p>I've been wanting to have a play with either Ruby or Python while at the same time I've been wanting to do a bit of Cocoa programming.</p>
<p>So I thought the best way to achieve both these goals is to develop something using either a Ruby or Python to Objective-C bridge (PyObjc or RubyCocoa).</p>
<p>I know that ... | 8 | 2009-01-09T00:16:24Z | 3,930,584 | <p>ObjectiveC is nowhere near as much fun or as productive as either Python or Ruby. That is why people want to pick a python or ruby with good Objective C access. Advising them to learn Objective C first misses the point imo. I have really good things to say about pyobjc. Its ability to interoperate painlessly wi... | 1 | 2010-10-14T06:19:39Z | [
"python",
"ruby",
"cocoa",
"pyobjc",
"ruby-cocoa"
] |
What is the easiest way to export data from a live google app engine application? | 426,820 | <p>I'm especially interested in solutions with source code available (django independency is a plus, but I'm willing to hack my way through)</p>
| 6 | 2009-01-09T02:09:04Z | 427,588 | <p>You can, of course, write your own handler. Other than that, your options currently are limited to:</p>
<ul>
<li><a href="http://github.com/fczuardi/gae-rest/tree/master">gae-rest</a>, which provides a RESTful interface to the datastore.</li>
<li><a href="http://code.google.com/p/approcket/">approcket</a>, a tool f... | 6 | 2009-01-09T10:12:41Z | [
"python",
"google-app-engine",
"frameworks"
] |
What is the easiest way to export data from a live google app engine application? | 426,820 | <p>I'm especially interested in solutions with source code available (django independency is a plus, but I'm willing to hack my way through)</p>
| 6 | 2009-01-09T02:09:04Z | 435,901 | <p><strong>Update</strong>: New version of Google AppEngine supports data import to and export from the online application natively. In their terms this is called <code>upload_data</code> and <code>download_data</code> respectively (names of subcommands of <code>appcfg.py</code>).</p>
<p>Please refer to Google documen... | 3 | 2009-01-12T16:09:03Z | [
"python",
"google-app-engine",
"frameworks"
] |
Scripting LMMS from Python | 427,037 | <p>Recently I <a href="http://stackoverflow.com/questions/267628/scripting-fruityloops-or-propellerheads-reason-from-vb-or-python">asked</a> about scripting FruityLoops or Reason from Python, which didn't turn up much.</p>
<p>Today I found <a href="http://lmms.sourceforge.net/" rel="nofollow">LMMS</a>, a free-software... | 1 | 2009-01-09T04:06:23Z | 427,330 | <p>It seems you can <a href="http://lmms.sourceforge.net/wiki/index.php?title=Plugin_development_tutorial" rel="nofollow">write plugins</a> for LMMS using C++. By <a href="http://www.python.org/doc/2.5.2/ext/embedding.html" rel="nofollow">embedding Python in the C++ plugin</a> you can effectively script the program in ... | 3 | 2009-01-09T07:33:10Z | [
"python",
"music"
] |
Scripting LMMS from Python | 427,037 | <p>Recently I <a href="http://stackoverflow.com/questions/267628/scripting-fruityloops-or-propellerheads-reason-from-vb-or-python">asked</a> about scripting FruityLoops or Reason from Python, which didn't turn up much.</p>
<p>Today I found <a href="http://lmms.sourceforge.net/" rel="nofollow">LMMS</a>, a free-software... | 1 | 2009-01-09T04:06:23Z | 427,841 | <p>Look at <a href="http://www.csounds.com/" rel="nofollow">http://www.csounds.com/</a> for an approach to scripting music synth programs in Python.</p>
| 0 | 2009-01-09T12:04:55Z | [
"python",
"music"
] |
Scripting LMMS from Python | 427,037 | <p>Recently I <a href="http://stackoverflow.com/questions/267628/scripting-fruityloops-or-propellerheads-reason-from-vb-or-python">asked</a> about scripting FruityLoops or Reason from Python, which didn't turn up much.</p>
<p>Today I found <a href="http://lmms.sourceforge.net/" rel="nofollow">LMMS</a>, a free-software... | 1 | 2009-01-09T04:06:23Z | 430,550 | <p>You can connect pretty much everything in LMMS to a MIDI input. Try that?</p>
| 0 | 2009-01-10T04:26:13Z | [
"python",
"music"
] |
Does anyone know of a Python equivalent of FMPP? | 427,095 | <p>Does anyone know of a Python equivalent for <a href="http://fmpp.sourceforge.net/" rel="nofollow">FMPP</a> the text file preprocessor?</p>
<p>Follow up: I am reading the docs and looking at the examples for the suggestions given. Just to expand. My usage of FMPP is to read in a data file (csv) and use multiple temp... | 4 | 2009-01-09T04:46:37Z | 427,131 | <p>You could give <a href="http://www.cheetahtemplate.org/" rel="nofollow">Cheetah</a> a try. I've used it before with some success.</p>
| 1 | 2009-01-09T05:04:40Z | [
"python",
"preprocessor",
"template-engine",
"freemarker",
"fmpp"
] |
Does anyone know of a Python equivalent of FMPP? | 427,095 | <p>Does anyone know of a Python equivalent for <a href="http://fmpp.sourceforge.net/" rel="nofollow">FMPP</a> the text file preprocessor?</p>
<p>Follow up: I am reading the docs and looking at the examples for the suggestions given. Just to expand. My usage of FMPP is to read in a data file (csv) and use multiple temp... | 4 | 2009-01-09T04:46:37Z | 427,300 | <p>Python has lots of templating engines. It depends on your exact needs.</p>
<p><a href="http://jinja.pocoo.org/2/" rel="nofollow">Jinja2</a> is a good one, for example. <a href="http://www.kid-templating.org/" rel="nofollow">Kid</a> is another.</p>
| 2 | 2009-01-09T07:15:03Z | [
"python",
"preprocessor",
"template-engine",
"freemarker",
"fmpp"
] |
Does anyone know of a Python equivalent of FMPP? | 427,095 | <p>Does anyone know of a Python equivalent for <a href="http://fmpp.sourceforge.net/" rel="nofollow">FMPP</a> the text file preprocessor?</p>
<p>Follow up: I am reading the docs and looking at the examples for the suggestions given. Just to expand. My usage of FMPP is to read in a data file (csv) and use multiple temp... | 4 | 2009-01-09T04:46:37Z | 427,827 | <p>Let me add <a href="http://makotemplates.org" rel="nofollow">Mako</a> Fine fast tool (and it even uses ${var} syntax).</p>
<p>Note: Mako, Jinja and Cheetah are <em>textual</em> languages (they process and generate text). I'd order them Mako > Jinja > Cheetah (in term of features and readability), but people's prefe... | 3 | 2009-01-09T11:59:40Z | [
"python",
"preprocessor",
"template-engine",
"freemarker",
"fmpp"
] |
Does anyone know of a Python equivalent of FMPP? | 427,095 | <p>Does anyone know of a Python equivalent for <a href="http://fmpp.sourceforge.net/" rel="nofollow">FMPP</a> the text file preprocessor?</p>
<p>Follow up: I am reading the docs and looking at the examples for the suggestions given. Just to expand. My usage of FMPP is to read in a data file (csv) and use multiple temp... | 4 | 2009-01-09T04:46:37Z | 427,870 | <p>I'm not sure exactly what FMPP does, but from a quick glance it seems like a template language.</p>
<p><a href="http://jinja.pocoo.org/2/" rel="nofollow">Jinja2</a> is an excellent template system for python.</p>
<p>sample:</p>
<pre><code><ul>
{% for item in list %}
<li> {{ item.title }} </... | 1 | 2009-01-09T12:19:06Z | [
"python",
"preprocessor",
"template-engine",
"freemarker",
"fmpp"
] |
What is a "slug" in Django? | 427,102 | <p>When I read Django code I often see in models what is called a "slug". I am not quite sure what this is, but I do know it has something to do with URLs. How and when is this slug-thing supposed to be used? </p>
<p>(I have read its definition in <a href="http://docs.djangoproject.com/en/dev/glossary/">this glossary<... | 273 | 2009-01-09T04:52:26Z | 427,111 | <p>From <a href="http://jeffcroft.com/blog/2006/may/02/django-non-programmers/">here</a>.</p>
<blockquote>
<p>âSlugâ is a newspaper term, but what
it means here is the final bit of the
URL. For example, a post with the
title, âA bit about Djangoâ would
become, âbit-about-djangoâ
automatically (... | 13 | 2009-01-09T04:56:10Z | [
"python",
"django",
"django-models",
"slug"
] |
What is a "slug" in Django? | 427,102 | <p>When I read Django code I often see in models what is called a "slug". I am not quite sure what this is, but I do know it has something to do with URLs. How and when is this slug-thing supposed to be used? </p>
<p>(I have read its definition in <a href="http://docs.djangoproject.com/en/dev/glossary/">this glossary<... | 273 | 2009-01-09T04:52:26Z | 427,125 | <p>It's a descriptive part of the URL that is there to make it more human descriptive, but without necessarily being required by the web server - in <a href="http://stackoverflow.com/questions/427102/in-django-what-is-a-slug">http://stackoverflow.com/questions/427102/in-django-what-is-a-slug</a> the slug is 'in-django-... | 13 | 2009-01-09T05:02:48Z | [
"python",
"django",
"django-models",
"slug"
] |
What is a "slug" in Django? | 427,102 | <p>When I read Django code I often see in models what is called a "slug". I am not quite sure what this is, but I do know it has something to do with URLs. How and when is this slug-thing supposed to be used? </p>
<p>(I have read its definition in <a href="http://docs.djangoproject.com/en/dev/glossary/">this glossary<... | 273 | 2009-01-09T04:52:26Z | 427,160 | <p>It's a way of generating a valid URL, generally using data already obtained. For instance, using the title of an article to generate a URL. I'd advise to generate the slug, using a function, given a title (or other piece of data), rather than setting it manually.</p>
<p>An example:</p>
<pre class="lang-html pretty... | 355 | 2009-01-09T05:31:47Z | [
"python",
"django",
"django-models",
"slug"
] |
What is a "slug" in Django? | 427,102 | <p>When I read Django code I often see in models what is called a "slug". I am not quite sure what this is, but I do know it has something to do with URLs. How and when is this slug-thing supposed to be used? </p>
<p>(I have read its definition in <a href="http://docs.djangoproject.com/en/dev/glossary/">this glossary<... | 273 | 2009-01-09T04:52:26Z | 427,201 | <p>As a bit of history, the term 'slug' comes from the world of newspaper editing.</p>
<p>It's the informal name given to a story during the production process. As the story winds its torturous path from beat reporter through to editor through to the "printing presses", this is the name it is referenced by, e.g., "Hav... | 34 | 2009-01-09T06:01:06Z | [
"python",
"django",
"django-models",
"slug"
] |
What is a "slug" in Django? | 427,102 | <p>When I read Django code I often see in models what is called a "slug". I am not quite sure what this is, but I do know it has something to do with URLs. How and when is this slug-thing supposed to be used? </p>
<p>(I have read its definition in <a href="http://docs.djangoproject.com/en/dev/glossary/">this glossary<... | 273 | 2009-01-09T04:52:26Z | 1,282,172 | <p>May I be complete to this :</p>
<p>The term <strong>"slug"</strong> has to do with casting metal, lead, in this case, out of which the press fonts were made of. Every Paper then, had its fonts factory, regularily, re-melted and recasted in fresh molds. Because after many prints they were worned out. Apprentice lik... | 58 | 2009-08-15T15:45:33Z | [
"python",
"django",
"django-models",
"slug"
] |
What is a "slug" in Django? | 427,102 | <p>When I read Django code I often see in models what is called a "slug". I am not quite sure what this is, but I do know it has something to do with URLs. How and when is this slug-thing supposed to be used? </p>
<p>(I have read its definition in <a href="http://docs.djangoproject.com/en/dev/glossary/">this glossary<... | 273 | 2009-01-09T04:52:26Z | 14,438,884 | <p>Also auto slug at django-admin. Added at ModelAdmin:</p>
<pre><code>prepopulated_fields = {'slug': ('title', )}
</code></pre>
<p>As here:</p>
<pre><code>class ArticleAdmin(admin.ModelAdmin):
list_display = ('title', 'slug')
search_fields = ('content', )
prepopulated_fields = {'slug': ('title', )}
</c... | 3 | 2013-01-21T12:42:44Z | [
"python",
"django",
"django-models",
"slug"
] |
What is a "slug" in Django? | 427,102 | <p>When I read Django code I often see in models what is called a "slug". I am not quite sure what this is, but I do know it has something to do with URLs. How and when is this slug-thing supposed to be used? </p>
<p>(I have read its definition in <a href="http://docs.djangoproject.com/en/dev/glossary/">this glossary<... | 273 | 2009-01-09T04:52:26Z | 25,808,438 | <p>Slug is a newspaper term. A slug is a short label for something, containing only letters, numbers, underscores or hyphens.Theyâre generally used in URLs.(as in django docs)</p>
<p>A slug field in Django is used to store and generate valid <a href="http://en.wikipedia.org/wiki/Uniform_resource_locator" rel="nofoll... | 6 | 2014-09-12T12:32:10Z | [
"python",
"django",
"django-models",
"slug"
] |
How do I timestamp simultaneous function calls in Python? | 427,152 | <p>I have a read function in a module.</p>
<p>If I perform that function simultaneously I need to timestamp it.</p>
<p>How do I do this?</p>
| -1 | 2009-01-09T05:21:49Z | 427,234 | <p>#!/usr/bin/env python</p>
<pre><code>import datetime
def timestampit(func):
def decorate(*args, **kwargs):
print datetime.datetime.now()
return func(*args, **kwargs)
return decorate
@timestampit
def hello():
print 'hello'
hello()
# Output:
# $ python test.py
# 2009-01-09 11:50:48.70... | 2 | 2009-01-09T06:21:01Z | [
"python",
"function-call",
"timestamping",
"simultaneous-calls"
] |
How do I timestamp simultaneous function calls in Python? | 427,152 | <p>I have a read function in a module.</p>
<p>If I perform that function simultaneously I need to timestamp it.</p>
<p>How do I do this?</p>
| -1 | 2009-01-09T05:21:49Z | 427,317 | <p>I'll offer a slightly different approach:</p>
<pre><code>import time
def timestampit(func):
def decorate(*args, **kwargs):
decorate.timestamp = time.time()
return func(*args, **kwargs)
return decorate
@timestampit
def hello():
print 'hello'
hello()
print hello.timestamp
time.sleep(1... | 6 | 2009-01-09T07:25:40Z | [
"python",
"function-call",
"timestamping",
"simultaneous-calls"
] |
How do I timestamp simultaneous function calls in Python? | 427,152 | <p>I have a read function in a module.</p>
<p>If I perform that function simultaneously I need to timestamp it.</p>
<p>How do I do this?</p>
| -1 | 2009-01-09T05:21:49Z | 427,619 | <p>If you're interested, there's <a href="http://wiki.python.org/moin/PythonDecorators" rel="nofollow">a wealth of information about decorators on the python wiki</a>.</p>
| 0 | 2009-01-09T10:27:02Z | [
"python",
"function-call",
"timestamping",
"simultaneous-calls"
] |
How do I timestamp simultaneous function calls in Python? | 427,152 | <p>I have a read function in a module.</p>
<p>If I perform that function simultaneously I need to timestamp it.</p>
<p>How do I do this?</p>
| -1 | 2009-01-09T05:21:49Z | 427,803 | <p>Some example
<a href="http://blogs.nuxeo.com/sections/blogs/tarek_ziade/archive/2005/09" rel="nofollow">code by Terik Ziade</a></p>
<p>(more polished version, which uses timeit module, can be found in his recent book Expert Python Programming)</p>
| 0 | 2009-01-09T11:50:52Z | [
"python",
"function-call",
"timestamping",
"simultaneous-calls"
] |
Unit testing and mocking email sender in Python with Google AppEngine | 427,400 | <p>I'm a newbie to python and the app engine.</p>
<p>I have this code that sends an email based on request params after some auth logic. in my Unit tests (i'm using <a href="http://code.google.com/p/gaeunit/" rel="nofollow">GAEUnit</a>), how do I confirm an email with specific contents were sent? - i.e. how do I mock ... | 5 | 2009-01-09T08:33:34Z | 427,418 | <p>A very short introduction provides <a href="http://pypi.python.org/pypi/MiniMock/1.0" rel="nofollow">PyPI: MiniMock 1.0</a>. It's a very small library to establish mocks.</p>
<ol>
<li>Inject your mock into the module, that should be mocked</li>
<li>Define, what your mock will return</li>
<li>Call the method</li>
<l... | 2 | 2009-01-09T08:46:09Z | [
"python",
"unit-testing",
"google-app-engine",
"mocking"
] |
Unit testing and mocking email sender in Python with Google AppEngine | 427,400 | <p>I'm a newbie to python and the app engine.</p>
<p>I have this code that sends an email based on request params after some auth logic. in my Unit tests (i'm using <a href="http://code.google.com/p/gaeunit/" rel="nofollow">GAEUnit</a>), how do I confirm an email with specific contents were sent? - i.e. how do I mock ... | 5 | 2009-01-09T08:33:34Z | 1,411,769 | <p>You could also override the <code>_GenerateLog</code> method in the <code>mail_stub</code> inside AppEngine.</p>
<p>Here is a parent TestCase class that I use as a mixin when testing that e-mails are sent:</p>
<pre><code>from google.appengine.api import apiproxy_stub_map, mail_stub
__all__ = ['MailTestCase']
cla... | 3 | 2009-09-11T15:50:57Z | [
"python",
"unit-testing",
"google-app-engine",
"mocking"
] |
Unit testing and mocking email sender in Python with Google AppEngine | 427,400 | <p>I'm a newbie to python and the app engine.</p>
<p>I have this code that sends an email based on request params after some auth logic. in my Unit tests (i'm using <a href="http://code.google.com/p/gaeunit/" rel="nofollow">GAEUnit</a>), how do I confirm an email with specific contents were sent? - i.e. how do I mock ... | 5 | 2009-01-09T08:33:34Z | 2,575,616 | <p>I used jgeewax's GAE Testbed with GAEUnit. Using GAEUnit instead of NoseGAE was easier for me since I already had GAEUnit in place. Here are the steps:</p>
<p><strong>Add GAEUnit to your app</strong></p>
<ol>
<li>Download the zipped archive of GAEUnit from <a href="http://code.google.com/p/gaeunit/" rel="nofollow"... | 1 | 2010-04-04T19:33:07Z | [
"python",
"unit-testing",
"google-app-engine",
"mocking"
] |
Unit testing and mocking email sender in Python with Google AppEngine | 427,400 | <p>I'm a newbie to python and the app engine.</p>
<p>I have this code that sends an email based on request params after some auth logic. in my Unit tests (i'm using <a href="http://code.google.com/p/gaeunit/" rel="nofollow">GAEUnit</a>), how do I confirm an email with specific contents were sent? - i.e. how do I mock ... | 5 | 2009-01-09T08:33:34Z | 7,579,200 | <p>Just use the following to get all messages sent since activating the mail stub.</p>
<pre><code>from google.appengine.api import apiproxy_stub_map
sent_messages = apiproxy_stub_map.apiproxy._APIProxyStubMap__stub_map['mail'].get_sent_messages()
</code></pre>
| 2 | 2011-09-28T06:34:36Z | [
"python",
"unit-testing",
"google-app-engine",
"mocking"
] |
Unit testing and mocking email sender in Python with Google AppEngine | 427,400 | <p>I'm a newbie to python and the app engine.</p>
<p>I have this code that sends an email based on request params after some auth logic. in my Unit tests (i'm using <a href="http://code.google.com/p/gaeunit/" rel="nofollow">GAEUnit</a>), how do I confirm an email with specific contents were sent? - i.e. how do I mock ... | 5 | 2009-01-09T08:33:34Z | 32,511,845 | <p>Google has a really simple way to do this in their <a href="https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/appengine/localtesting/test_mail.py" rel="nofollow">documentation</a>.</p>
<p>You create a testbed and mail stub in your setup like this:</p>
<pre><code>self.testbed = testbed.Testbed(... | 1 | 2015-09-10T21:24:47Z | [
"python",
"unit-testing",
"google-app-engine",
"mocking"
] |
How can I get the source code of a Python function? | 427,453 | <p>Suppose I have a Python function as defined below:</p>
<pre><code>def foo(arg1,arg2):
#do something with args
a = arg1 + arg2
return a
</code></pre>
<p>I can get the name of the function using <code>foo.func_name</code>. How can I programmatically get its source code, as I typed above?</p>
| 127 | 2009-01-09T09:02:37Z | 427,504 | <p>The <a href="http://docs.python.org/library/inspect.html?highlight=inspect#retrieving-source-code">inspect module</a> has methods for retreiving source code from python objects. Seemingly it only works if the source is located in a file though. If you had that I guess you wouldn't need to get the source from the obj... | 120 | 2009-01-09T09:25:54Z | [
"python",
"function"
] |
How can I get the source code of a Python function? | 427,453 | <p>Suppose I have a Python function as defined below:</p>
<pre><code>def foo(arg1,arg2):
#do something with args
a = arg1 + arg2
return a
</code></pre>
<p>I can get the name of the function using <code>foo.func_name</code>. How can I programmatically get its source code, as I typed above?</p>
| 127 | 2009-01-09T09:02:37Z | 427,524 | <p>I <em>believe</em> that variable names aren't stored in pyc/pyd/pyo files, so you can not retrieve the exact code lines if you don't have source files.</p>
| 0 | 2009-01-09T09:38:47Z | [
"python",
"function"
] |
How can I get the source code of a Python function? | 427,453 | <p>Suppose I have a Python function as defined below:</p>
<pre><code>def foo(arg1,arg2):
#do something with args
a = arg1 + arg2
return a
</code></pre>
<p>I can get the name of the function using <code>foo.func_name</code>. How can I programmatically get its source code, as I typed above?</p>
| 127 | 2009-01-09T09:02:37Z | 427,533 | <p>If the function is from a source file available on the filesystem, then <a href="https://docs.python.org/3/library/inspect.html#inspect.getsourcelines"><code>inspect.getsourcelines(foo)</code></a> might be of help.</p>
<p>I believe that if the function is compiled from a string, stream or imported from a compiled f... | 180 | 2009-01-09T09:44:38Z | [
"python",
"function"
] |
How can I get the source code of a Python function? | 427,453 | <p>Suppose I have a Python function as defined below:</p>
<pre><code>def foo(arg1,arg2):
#do something with args
a = arg1 + arg2
return a
</code></pre>
<p>I can get the name of the function using <code>foo.func_name</code>. How can I programmatically get its source code, as I typed above?</p>
| 127 | 2009-01-09T09:02:37Z | 10,196,254 | <p>If you're strictly defining the function yourself and it's a relatively short definition, a solution without dependencies would be to define the function in a string and assign the eval() of the expression to your function. </p>
<p>E.g. </p>
<pre><code>funcstring = 'lambda x: x> 5'
func = eval(funcstring)
</cod... | 1 | 2012-04-17T17:44:09Z | [
"python",
"function"
] |
How can I get the source code of a Python function? | 427,453 | <p>Suppose I have a Python function as defined below:</p>
<pre><code>def foo(arg1,arg2):
#do something with args
a = arg1 + arg2
return a
</code></pre>
<p>I can get the name of the function using <code>foo.func_name</code>. How can I programmatically get its source code, as I typed above?</p>
| 127 | 2009-01-09T09:02:37Z | 17,358,307 | <p><code>dis</code> is your friend if the source code is not available:</p>
<pre><code>>>> import dis
>>> def foo(arg1,arg2):
... #do something with args
... a = arg1 + arg2
... return a
...
>>> dis.dis(foo)
3 0 LOAD_FAST 0 (arg1)
3 LOAD_F... | 45 | 2013-06-28T06:11:18Z | [
"python",
"function"
] |
How can I get the source code of a Python function? | 427,453 | <p>Suppose I have a Python function as defined below:</p>
<pre><code>def foo(arg1,arg2):
#do something with args
a = arg1 + arg2
return a
</code></pre>
<p>I can get the name of the function using <code>foo.func_name</code>. How can I programmatically get its source code, as I typed above?</p>
| 127 | 2009-01-09T09:02:37Z | 21,339,166 | <p>While I'd generally agree that <code>inspect</code> is a good answer, I'd disagree that you can't get the source code of objects defined in the interpreter. If you use <code>dill.source.getsource</code> from <a href="https://github.com/uqfoundation/dill"><code>dill</code></a>, you can get the source of functions an... | 27 | 2014-01-24T17:51:36Z | [
"python",
"function"
] |
How can I get the source code of a Python function? | 427,453 | <p>Suppose I have a Python function as defined below:</p>
<pre><code>def foo(arg1,arg2):
#do something with args
a = arg1 + arg2
return a
</code></pre>
<p>I can get the name of the function using <code>foo.func_name</code>. How can I programmatically get its source code, as I typed above?</p>
| 127 | 2009-01-09T09:02:37Z | 25,107,178 | <p>To expand on runeh's answer:</p>
<pre><code>>>> def foo(a):
... x = 2
... return x + a
>>> import inspect
>>> inspect.getsource(foo)
u'def foo(a):\n x = 2\n return x + a\n'
print inspect.getsource(foo)
def foo(a):
x = 2
return x + a
</code></pre>
<p>EDIT: As pointed ... | 14 | 2014-08-03T17:23:42Z | [
"python",
"function"
] |
How can I get the source code of a Python function? | 427,453 | <p>Suppose I have a Python function as defined below:</p>
<pre><code>def foo(arg1,arg2):
#do something with args
a = arg1 + arg2
return a
</code></pre>
<p>I can get the name of the function using <code>foo.func_name</code>. How can I programmatically get its source code, as I typed above?</p>
| 127 | 2009-01-09T09:02:37Z | 37,111,797 | <p>If you are using IPython, then you need to type "foo??"</p>
<pre><code>In [19]: foo??
Signature: foo(arg1, arg2)
Source:
def foo(arg1,arg2):
#do something with args
a = arg1 + arg2
return a
File: ~/Desktop/<ipython-input-18-3174e3126506>
Type: function
</code></pre>
| 12 | 2016-05-09T09:11:05Z | [
"python",
"function"
] |
Ordered lists in django | 428,149 | <p>i have very simple problem. I need to create model, that represent element of ordered list. This model can be implemented like this:</p>
<pre><code>class Item(models.Model):
data = models.TextField()
order = models.IntegerField()
</code></pre>
<p>or like this:</p>
<pre><code>class Item(models.Model):
... | 10 | 2009-01-09T14:06:13Z | 428,165 | <p>That depends on what you want to do. </p>
<p>The first one seems better to make a single query in the database and get all data in the correct order</p>
<p>The second one seems better to insert an element between two existing elements (because in the first one you'd have to change a lot of items if the numbers are... | 6 | 2009-01-09T14:12:35Z | [
"python",
"django",
"django-models"
] |
Ordered lists in django | 428,149 | <p>i have very simple problem. I need to create model, that represent element of ordered list. This model can be implemented like this:</p>
<pre><code>class Item(models.Model):
data = models.TextField()
order = models.IntegerField()
</code></pre>
<p>or like this:</p>
<pre><code>class Item(models.Model):
... | 10 | 2009-01-09T14:06:13Z | 428,189 | <p>Essentially, the second solution you propose is a linked list. Linked list implemented at the database level are usually not a good idea. To retrieve a list of <code>n</code> elements, you will need <code>n</code> database access (or use complicated queries). Performance wise, retrieving a list in O(n) is awfully no... | 18 | 2009-01-09T14:17:26Z | [
"python",
"django",
"django-models"
] |
Ordered lists in django | 428,149 | <p>i have very simple problem. I need to create model, that represent element of ordered list. This model can be implemented like this:</p>
<pre><code>class Item(models.Model):
data = models.TextField()
order = models.IntegerField()
</code></pre>
<p>or like this:</p>
<pre><code>class Item(models.Model):
... | 10 | 2009-01-09T14:06:13Z | 428,460 | <p>There is another solution.</p>
<pre><code>class Item(models.Model):
data = models.TextField()
</code></pre>
<p>You can just pickle or marshal Python list into the data field and the load it up. This one is good for updating and reading, but not for searching e.g. fetching all lists that contain a specific item... | -6 | 2009-01-09T15:22:38Z | [
"python",
"django",
"django-models"
] |
Why do managed attributes just work for class attributes and not for instance attributes in python? | 428,264 | <p>To illustrate the question check the following code:</p>
<pre><code>class MyDescriptor(object):
def __get__(self, obj, type=None):
print "get", self, obj, type
return self._v
def __set__(self, obj, value):
self._v = value
print "set", self, obj, value
return None
class SomeClass1(object):
... | 2 | 2009-01-09T14:38:13Z | 428,357 | <p>To answer your second question, where is <code>_v</code>?</p>
<p>Your version of the descriptor keeps <code>_v</code> in the descriptor itself. Each instance of the descriptor (the class-level instance <code>SomeClass1</code>, and all of the object-level instances in objects of class <code>SomeClass2</code> will ... | 3 | 2009-01-09T14:55:59Z | [
"python",
"attributes",
"descriptor"
] |
Why do managed attributes just work for class attributes and not for instance attributes in python? | 428,264 | <p>To illustrate the question check the following code:</p>
<pre><code>class MyDescriptor(object):
def __get__(self, obj, type=None):
print "get", self, obj, type
return self._v
def __set__(self, obj, value):
self._v = value
print "set", self, obj, value
return None
class SomeClass1(object):
... | 2 | 2009-01-09T14:38:13Z | 428,423 | <p>You should read <a href="http://docs.python.org/reference/datamodel.html#implementing-descriptors" rel="nofollow">this</a> and <a href="http://users.rcn.com/python/download/Descriptor.htm" rel="nofollow">this</a>.</p>
<p>It overwrites the function because you didn't overload the <code>__set__</code> and <code>__get... | 3 | 2009-01-09T15:11:27Z | [
"python",
"attributes",
"descriptor"
] |
Why do managed attributes just work for class attributes and not for instance attributes in python? | 428,264 | <p>To illustrate the question check the following code:</p>
<pre><code>class MyDescriptor(object):
def __get__(self, obj, type=None):
print "get", self, obj, type
return self._v
def __set__(self, obj, value):
self._v = value
print "set", self, obj, value
return None
class SomeClass1(object):
... | 2 | 2009-01-09T14:38:13Z | 431,475 | <p>I found <strong>_v</strong> of <strong>x1</strong>: It is in <strong>SomeClass1.__dict__['m']._v</strong></p>
<p>For the version suggested by S.Lott within the other answer: <strong>_v</strong> is in <strong>x1._v</strong></p>
| 0 | 2009-01-10T18:17:28Z | [
"python",
"attributes",
"descriptor"
] |
How to programmatically change urls of images in word documents | 428,308 | <p>I have a set of word documents that contains a lot of non-embedded images in them. The url that the images point to no longer exist. I would like to programmatically change the domain name of the url to something else. How can I go about doing this in Java or Python ?</p>
| 1 | 2009-01-09T14:46:36Z | 428,338 | <p>Perhaps the <a href="http://download.microsoft.com/download/0/B/E/0BE8BDD7-E5E8-422A-ABFD-4342ED7AD886/Word97-2007BinaryFileFormat(doc)Specification.pdf" rel="nofollow">Microsoft Office Word binary file format specification</a> could help you here, though someone who already did stuff like this might come up with a ... | 0 | 2009-01-09T14:53:03Z | [
"java",
"python",
"image",
"ms-word"
] |
How to programmatically change urls of images in word documents | 428,308 | <p>I have a set of word documents that contains a lot of non-embedded images in them. The url that the images point to no longer exist. I would like to programmatically change the domain name of the url to something else. How can I go about doing this in Java or Python ?</p>
| 1 | 2009-01-09T14:46:36Z | 428,525 | <p>This is the sort of thing that VBA is for:</p>
<pre><code>Sub HlinkChanger()
Dim oRange As Word.Range
Dim oField As Field
Dim link As Variant
With ActiveDocument
.Range.AutoFormat
For Each oRange In .StoryRanges
For Each oFld In oRange.Fields
If oFld.Type = wdFieldHyperlink Then
... | 1 | 2009-01-09T15:38:07Z | [
"java",
"python",
"image",
"ms-word"
] |
How to programmatically change urls of images in word documents | 428,308 | <p>I have a set of word documents that contains a lot of non-embedded images in them. The url that the images point to no longer exist. I would like to programmatically change the domain name of the url to something else. How can I go about doing this in Java or Python ?</p>
| 1 | 2009-01-09T14:46:36Z | 430,717 | <p>You want to do this in Java or Python. Try OpenOffice.
In OpenOffice, you can insert Java or Python code as a "Makro".</p>
<p>I'm sure there will be a possibility to change the image URLs.</p>
| 0 | 2009-01-10T07:45:26Z | [
"java",
"python",
"image",
"ms-word"
] |
How to programmatically change urls of images in word documents | 428,308 | <p>I have a set of word documents that contains a lot of non-embedded images in them. The url that the images point to no longer exist. I would like to programmatically change the domain name of the url to something else. How can I go about doing this in Java or Python ?</p>
| 1 | 2009-01-09T14:46:36Z | 1,615,775 | <p>The VBA answer is the closest because this is best done using the Microsoft Word COM API. However, you can use this just as well from Python. I've used it myself to import data into a database from hundreds of forms that were Word Documents.</p>
<p><a href="http://snippets.dzone.com/posts/show/2037" rel="nofollow">... | 0 | 2009-10-23T20:41:28Z | [
"java",
"python",
"image",
"ms-word"
] |
Measure load time for python cgi script? | 428,704 | <p>I use python cgi for our intranet application.</p>
<p>When I measure time, the script takes 4s to finish. But after that, it still takes another 11s to show the screen in the browser.
The screen is build with tables (size: 10 KB, 91 KB uncompressed) and has a large css file (5 KB, 58 KB uncompressed).</p>
<p>I us... | 2 | 2009-01-09T16:19:11Z | 428,767 | <p>I think I'd grab a copy of Ethereal and watch the TCP connection between the browser and the script, if I were concerned about whether the server is not getting its job done in an acceptable amount of time. If you see the TCP socket close before that 11s gap, you know that your issue is entirely on the browser side... | 1 | 2009-01-09T16:31:46Z | [
"python",
"html",
"css",
"browser",
"cgi"
] |
Measure load time for python cgi script? | 428,704 | <p>I use python cgi for our intranet application.</p>
<p>When I measure time, the script takes 4s to finish. But after that, it still takes another 11s to show the screen in the browser.
The screen is build with tables (size: 10 KB, 91 KB uncompressed) and has a large css file (5 KB, 58 KB uncompressed).</p>
<p>I us... | 2 | 2009-01-09T16:19:11Z | 428,832 | <p>with that much html to render I would also consider the speed of the computer. you can test this by saving the html file and opening it from your local hard drive :)</p>
| 1 | 2009-01-09T16:51:45Z | [
"python",
"html",
"css",
"browser",
"cgi"
] |
How can I get the created date of a file on the web (with Python)? | 428,895 | <p>I have a python application that relies on a file that is downloaded by a client from a website.</p>
<p>The website is not under my control and has no API to check for a "latest version" of the file.</p>
<p>Is there a simple way to access the file (in python) via a URL and check it's date (or size) without having ... | 1 | 2009-01-09T17:11:15Z | 428,899 | <p>Check the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.29" rel="nofollow">Last-Modified</a> header.</p>
<p>EDIT: Try <a href="http://www.voidspace.org.uk/python/articles/urllib2.shtml#introduction" rel="nofollow">urllib2</a>.</p>
<p>EDIT 2: This <a href="http://www.artima.com/forums/flat.j... | 4 | 2009-01-09T17:13:09Z | [
"python",
"http"
] |
How can I get the created date of a file on the web (with Python)? | 428,895 | <p>I have a python application that relies on a file that is downloaded by a client from a website.</p>
<p>The website is not under my control and has no API to check for a "latest version" of the file.</p>
<p>Is there a simple way to access the file (in python) via a URL and check it's date (or size) without having ... | 1 | 2009-01-09T17:11:15Z | 428,951 | <p>There is no reliable way to do this. For all you know, the file can be created on the fly by the web server and the question "how old is this file" is not meaningful. The webserver may choose to provide Last-Modified header, but it could tell you whatever it wants.</p>
| 5 | 2009-01-09T17:29:52Z | [
"python",
"http"
] |
How can I get the created date of a file on the web (with Python)? | 428,895 | <p>I have a python application that relies on a file that is downloaded by a client from a website.</p>
<p>The website is not under my control and has no API to check for a "latest version" of the file.</p>
<p>Is there a simple way to access the file (in python) via a URL and check it's date (or size) without having ... | 1 | 2009-01-09T17:11:15Z | 428,986 | <p>In HTTP 1.1, the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1" rel="nofollow">Content-Disposition header field</a> is intended to hold this kind of information in the <code>creation-date</code> parameter (see <a href="http://www.ietf.org/rfc/rfc2183.txt" rel="nofollow">RFC 2183</a>).</p>... | 2 | 2009-01-09T17:38:47Z | [
"python",
"http"
] |
How can I get the created date of a file on the web (with Python)? | 428,895 | <p>I have a python application that relies on a file that is downloaded by a client from a website.</p>
<p>The website is not under my control and has no API to check for a "latest version" of the file.</p>
<p>Is there a simple way to access the file (in python) via a URL and check it's date (or size) without having ... | 1 | 2009-01-09T17:11:15Z | 429,239 | <p>I built a tool that does this based on etags. Sounds a lot like what you're describing:</p>
<p><a href="http://github.com/dustin/pfetch" rel="nofollow">pfetch</a> is a twisted tool that does this on a schedule and can run with many, many URLs and trigger events upon change (post-download). It's pretty simple, but... | 0 | 2009-01-09T18:50:27Z | [
"python",
"http"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.