title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
SimpleParse non-deterministic grammar until runtime | 1,537,708 | <p>I'm working on a basic networking protocol in Python, which should be able to transfer both ASCII strings (read: EOL-terminated) and binary data.
For the latter to be possible, I chose to create the grammar such that it contains the number of bytes to come which are going to be binary.</p>
<p>For SimpleParse, the g... | 1 | 2009-10-08T13:11:07Z | 1,628,368 | <p>If you want your application to be portable and reliable I would suggest you pass only standard ASCII characters over the wire.</p>
<p>Different computer architectures have different binary representaions, different word sizes, different character sets. There are three approaches to dealing with this.</p>
<p>FIrst... | 1 | 2009-10-27T01:55:42Z | [
"python",
"parsing",
"text-parsing"
] |
Python multiprocessing and database access with pyodbc "is not safe"? | 1,537,809 | <p><strong>The Problem:</strong></p>
<p>I am getting the following traceback and don't understand what it means or how to fix it:</p>
<pre><code>Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python26\lib\multiprocessing\forking.py", line 342, in main
self = load(... | 9 | 2009-10-08T13:29:43Z | 1,537,840 | <p>The error is raised within the <code>pickle</code> module, so somewhere your DB-Cursor object gets pickled and unpickled (serialized to storage and unserialized to the Python object again).</p>
<p>I guess that <code>pyodbc.Cursor</code> does not support pickling. Why should you try to persist the cursor object anyw... | 3 | 2009-10-08T13:36:22Z | [
"python",
"sql-server",
"multiprocessing",
"pickle",
"pyodbc"
] |
Python multiprocessing and database access with pyodbc "is not safe"? | 1,537,809 | <p><strong>The Problem:</strong></p>
<p>I am getting the following traceback and don't understand what it means or how to fix it:</p>
<pre><code>Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python26\lib\multiprocessing\forking.py", line 342, in main
self = load(... | 9 | 2009-10-08T13:29:43Z | 1,538,008 | <p>Multiprocessing relies on pickling to communicate objects between processes. The pyodbc connection and cursor objects can not be pickled.</p>
<pre><code>>>> cPickle.dumps(aCursor)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.5/copy_reg.py"... | 6 | 2009-10-08T14:02:46Z | [
"python",
"sql-server",
"multiprocessing",
"pickle",
"pyodbc"
] |
Python multiprocessing and database access with pyodbc "is not safe"? | 1,537,809 | <p><strong>The Problem:</strong></p>
<p>I am getting the following traceback and don't understand what it means or how to fix it:</p>
<pre><code>Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python26\lib\multiprocessing\forking.py", line 342, in main
self = load(... | 9 | 2009-10-08T13:29:43Z | 26,644,234 | <p><a href="http://pyodbc.googlecode.com/git-history/c3f6b46d8a4f73722439b4755ef5df42adff81d9/web/docs.html#pyodbc" rel="nofollow">pyodbc</a> has Python DB-API <a href="http://legacy.python.org/dev/peps/pep-0249/#threadsafety" rel="nofollow">threadsafety level 1</a>. This means threads cannot share connections, and it'... | 1 | 2014-10-30T02:50:08Z | [
"python",
"sql-server",
"multiprocessing",
"pickle",
"pyodbc"
] |
Read bytes from string as floats | 1,537,862 | <p>I've got a python webserver where small binary files are POST:ed. The posted data is represented as strings. I want to examine the contents of these strings. But to do that, I need to convert each 4 bytes to floats (little endian). How do you do that?</p>
| 1 | 2009-10-08T13:39:32Z | 1,537,884 | <p>You use the <a href="http://docs.python.org/library/struct.html" rel="nofollow">struct</a> module:</p>
<pre><code>>>> import struct
>>> struct.unpack_from("f", "\43\a3\12\32")
(8.6198787687447256e-33,)
</code></pre>
| 7 | 2009-10-08T13:43:19Z | [
"python",
"string",
"byte"
] |
Read bytes from string as floats | 1,537,862 | <p>I've got a python webserver where small binary files are POST:ed. The posted data is represented as strings. I want to examine the contents of these strings. But to do that, I need to convert each 4 bytes to floats (little endian). How do you do that?</p>
| 1 | 2009-10-08T13:39:32Z | 1,537,927 | <p>The <a href="http://construct.wikispaces.com/" rel="nofollow">construct</a> module might also be a handy way to do this. It should be easy to adapt <a href="http://construct.wikispaces.com/tut-basics" rel="nofollow">this example</a> to your needs:</p>
<pre><code># [U]nsigned, [L]ittle endian, 16 bit wide integer (p... | 1 | 2009-10-08T13:50:47Z | [
"python",
"string",
"byte"
] |
Read bytes from string as floats | 1,537,862 | <p>I've got a python webserver where small binary files are POST:ed. The posted data is represented as strings. I want to examine the contents of these strings. But to do that, I need to convert each 4 bytes to floats (little endian). How do you do that?</p>
| 1 | 2009-10-08T13:39:32Z | 1,538,312 | <p>While <code>struct</code> is best for unpacking collection of "scalar" binary values, when you what you have is a sequence of 4-byte binary floats in a string one after the other, the <a href="http://docs.python.org/library/array.html" rel="nofollow">array</a> module is ideal. Specifically, it's as simple as:</p>
... | 5 | 2009-10-08T14:49:02Z | [
"python",
"string",
"byte"
] |
How to redirect and then display errors with Google App Engine | 1,538,287 | <p>I'm working on a Google App Engine project that collects stories submitted by users.</p>
<p>This is how I handle submission errors in the post method of my Request Handler:</p>
<pre><code># get the title and content using self.request.get()
errors = []
if not title:
errors.append("Please enter a title.")
if no... | 1 | 2009-10-08T14:44:43Z | 1,538,438 | <p>You could redirect to /Share including the errors in a GET variable in the URL, if you're absolutely sure you need to use separate URLs. Of course, this makes your URL ugly since it now has all of the error information in it.</p>
<p>Another option would be to redirect back to Share and have the errors stored in co... | 1 | 2009-10-08T15:08:08Z | [
"python",
"google-app-engine"
] |
How to redirect and then display errors with Google App Engine | 1,538,287 | <p>I'm working on a Google App Engine project that collects stories submitted by users.</p>
<p>This is how I handle submission errors in the post method of my Request Handler:</p>
<pre><code># get the title and content using self.request.get()
errors = []
if not title:
errors.append("Please enter a title.")
if no... | 1 | 2009-10-08T14:44:43Z | 1,540,080 | <p>There's no 'clean' way of doing this, because you cannot redirect POST requests (and have the redirected request also make a POST). The standard - and cleanest - approach is to have the same URL display the form when fetched with GET, and accept the data when fetched with POST.</p>
| 1 | 2009-10-08T20:00:59Z | [
"python",
"google-app-engine"
] |
QGraphicsView with automatic items placing | 1,538,308 | <p>I would like to write an asset browser using QGraphicsView. It's a little different from examples using QGraphicsView and QGraphicsItems, because I want only one scrollbar and I want items to move automatically, when the viewport size changes. For example, when viewport width is large enough to display 4 asssets, th... | 2 | 2009-10-08T14:48:48Z | 1,538,432 | <p>QGraphicsView supports layouts. What you have to do is implement your own layout manager, inheriting from QGraphicsLayout.</p>
<p>For the layout you require, take a look at the Flow Layout example of Qt. Converting that example will give you a QGraphicsFlowLayout. Add your QGraphicsItems to this layout and set your... | 5 | 2009-10-08T15:06:32Z | [
"python",
"qt",
"pyqt",
"qgraphicsview"
] |
QGraphicsView with automatic items placing | 1,538,308 | <p>I would like to write an asset browser using QGraphicsView. It's a little different from examples using QGraphicsView and QGraphicsItems, because I want only one scrollbar and I want items to move automatically, when the viewport size changes. For example, when viewport width is large enough to display 4 asssets, th... | 2 | 2009-10-08T14:48:48Z | 1,538,455 | <p>I would use a custom layout to do this. Try to create your custom Layout class that inherits from QGraphicsLayout and manage the way it is placing items.</p>
| 0 | 2009-10-08T15:10:41Z | [
"python",
"qt",
"pyqt",
"qgraphicsview"
] |
QGraphicsView with automatic items placing | 1,538,308 | <p>I would like to write an asset browser using QGraphicsView. It's a little different from examples using QGraphicsView and QGraphicsItems, because I want only one scrollbar and I want items to move automatically, when the viewport size changes. For example, when viewport width is large enough to display 4 asssets, th... | 2 | 2009-10-08T14:48:48Z | 1,538,918 | <p>It sounds to me you want a list, not a graphics view. A list can be set to display things wrapping around like you desire. See the <a href="http://doc.trolltech.com/4.5/itemviews-puzzle.html" rel="nofollow">puzzle example</a>, paying attention to the list of puzzle pieces on the left. It looks pretty simple to se... | 1 | 2009-10-08T16:23:17Z | [
"python",
"qt",
"pyqt",
"qgraphicsview"
] |
How can I get the name of an object in Python? | 1,538,342 | <p>Is there any way to get the name of an object in Python? For instance:</p>
<pre><code>my_list = [x, y, z] # x, y, z have been previously defined
for bla in my_list:
print "handling object ", name(bla) # <--- what would go instead of `name`?
# do something to bla
</code></pre>
<p><strong>Edit:</strong>... | 11 | 2009-10-08T14:54:21Z | 1,538,380 | <p>Objects do not necessarily have names in python, so you can't get the name.
It's not unusual for objects to have a <code>__name__</code> attribute in those cases that they do have a name, but this is not a part of standard python, and most built in types do not have one.</p>
<p>When you create a variable, like the ... | 17 | 2009-10-08T14:58:40Z | [
"python",
"introspection"
] |
How can I get the name of an object in Python? | 1,538,342 | <p>Is there any way to get the name of an object in Python? For instance:</p>
<pre><code>my_list = [x, y, z] # x, y, z have been previously defined
for bla in my_list:
print "handling object ", name(bla) # <--- what would go instead of `name`?
# do something to bla
</code></pre>
<p><strong>Edit:</strong>... | 11 | 2009-10-08T14:54:21Z | 1,538,399 | <p>That's not really possible, as there could be multiple variables that have the same value, or a value might have no variable, or a value might have the same value as a variable only by chance.</p>
<p>If you really want to do that, you can use</p>
<pre><code>def variable_for_value(value):
for n,v in globals().i... | 5 | 2009-10-08T15:01:40Z | [
"python",
"introspection"
] |
How can I get the name of an object in Python? | 1,538,342 | <p>Is there any way to get the name of an object in Python? For instance:</p>
<pre><code>my_list = [x, y, z] # x, y, z have been previously defined
for bla in my_list:
print "handling object ", name(bla) # <--- what would go instead of `name`?
# do something to bla
</code></pre>
<p><strong>Edit:</strong>... | 11 | 2009-10-08T14:54:21Z | 1,538,466 | <p>Variable names can be found in the globals() and locals() dicts. But they won't give you what you're looking for above. "bla" will contain the value of each item of my_list, not the variable.</p>
| 0 | 2009-10-08T15:12:23Z | [
"python",
"introspection"
] |
How can I get the name of an object in Python? | 1,538,342 | <p>Is there any way to get the name of an object in Python? For instance:</p>
<pre><code>my_list = [x, y, z] # x, y, z have been previously defined
for bla in my_list:
print "handling object ", name(bla) # <--- what would go instead of `name`?
# do something to bla
</code></pre>
<p><strong>Edit:</strong>... | 11 | 2009-10-08T14:54:21Z | 1,538,772 | <p>Note that while, as noted, objects in general do not and cannot know what variables are bound to them, functions defined with <code>def</code> do have names in the <code>__name__</code> attribute (the name used in <code>def</code>). Also if the functions are defined in the same module (as in your example) then <cod... | 1 | 2009-10-08T16:03:22Z | [
"python",
"introspection"
] |
How can I get the name of an object in Python? | 1,538,342 | <p>Is there any way to get the name of an object in Python? For instance:</p>
<pre><code>my_list = [x, y, z] # x, y, z have been previously defined
for bla in my_list:
print "handling object ", name(bla) # <--- what would go instead of `name`?
# do something to bla
</code></pre>
<p><strong>Edit:</strong>... | 11 | 2009-10-08T14:54:21Z | 1,539,112 | <p>Generally when you are wanting to do something like this, you create a class to hold all of these functions and name them with some clear prefix <code>cmd_</code> or the like. You then take the string from the command, and try to get that attribute from the class with the <code>cmd_</code> prefixed to it. Now you ... | 0 | 2009-10-08T16:53:33Z | [
"python",
"introspection"
] |
How can I get the name of an object in Python? | 1,538,342 | <p>Is there any way to get the name of an object in Python? For instance:</p>
<pre><code>my_list = [x, y, z] # x, y, z have been previously defined
for bla in my_list:
print "handling object ", name(bla) # <--- what would go instead of `name`?
# do something to bla
</code></pre>
<p><strong>Edit:</strong>... | 11 | 2009-10-08T14:54:21Z | 1,539,123 | <p>Here's another way to think about it. Suppose there were a <code>name()</code> function that returned the name of its argument. Given the following code:</p>
<pre><code>def f(a):
return a
b = "x"
c = b
d = f(c)
e = [f(b), f(c), f(d)]
</code></pre>
<p>What should <code>name(e[2])</code> return, and why?</p>... | 1 | 2009-10-08T16:54:37Z | [
"python",
"introspection"
] |
How can I get the name of an object in Python? | 1,538,342 | <p>Is there any way to get the name of an object in Python? For instance:</p>
<pre><code>my_list = [x, y, z] # x, y, z have been previously defined
for bla in my_list:
print "handling object ", name(bla) # <--- what would go instead of `name`?
# do something to bla
</code></pre>
<p><strong>Edit:</strong>... | 11 | 2009-10-08T14:54:21Z | 1,539,174 | <blockquote>
<p>And the reason I want to have the name of the function is because I want to create <code>fun_dict</code> without writing the names of the functions twice, since that seems like a good way to create bugs.</p>
</blockquote>
<p>For this purpose you have a wonderful <a href="http://docs.python.org/librar... | 1 | 2009-10-08T17:02:37Z | [
"python",
"introspection"
] |
How can I get the name of an object in Python? | 1,538,342 | <p>Is there any way to get the name of an object in Python? For instance:</p>
<pre><code>my_list = [x, y, z] # x, y, z have been previously defined
for bla in my_list:
print "handling object ", name(bla) # <--- what would go instead of `name`?
# do something to bla
</code></pre>
<p><strong>Edit:</strong>... | 11 | 2009-10-08T14:54:21Z | 1,539,517 | <p>Use a reverse dict.</p>
<pre><code>fun_dict = {'fun1': fun1,
'fun2': fun2,
'fun3': fun3}
r_dict = dict(zip(fun_dict.values(), fun_dict.keys()))
</code></pre>
<p>The reverse dict will map each function reference to the exact name you gave it in fun_dict, which may or may not be the name you... | 1 | 2009-10-08T18:03:44Z | [
"python",
"introspection"
] |
How can I get the name of an object in Python? | 1,538,342 | <p>Is there any way to get the name of an object in Python? For instance:</p>
<pre><code>my_list = [x, y, z] # x, y, z have been previously defined
for bla in my_list:
print "handling object ", name(bla) # <--- what would go instead of `name`?
# do something to bla
</code></pre>
<p><strong>Edit:</strong>... | 11 | 2009-10-08T14:54:21Z | 16,139,159 | <p>This one-liner works, for all types of objects, as long as they are in <code>globals()</code> dict, which they should be:</p>
<pre><code>def name_of_global_obj(xx):
return [objname for objname,oid in globals().items() if id(oid)==id(xx)][0]
</code></pre>
<p>or, equivalently:</p>
<pre><code> def name_of_glo... | 1 | 2013-04-22T03:53:40Z | [
"python",
"introspection"
] |
How can I get the name of an object in Python? | 1,538,342 | <p>Is there any way to get the name of an object in Python? For instance:</p>
<pre><code>my_list = [x, y, z] # x, y, z have been previously defined
for bla in my_list:
print "handling object ", name(bla) # <--- what would go instead of `name`?
# do something to bla
</code></pre>
<p><strong>Edit:</strong>... | 11 | 2009-10-08T14:54:21Z | 21,339,843 | <p>If you are looking to get the names of functions or lambdas or other function-like objects that are defined in the interpreter, you can use <code>dill.source.getname</code> from <a href="https://github.com/uqfoundation/dill" rel="nofollow"><code>dill</code></a>. It pretty much looks for the <code>__name__</code> me... | 2 | 2014-01-24T18:30:51Z | [
"python",
"introspection"
] |
How can I get the name of an object in Python? | 1,538,342 | <p>Is there any way to get the name of an object in Python? For instance:</p>
<pre><code>my_list = [x, y, z] # x, y, z have been previously defined
for bla in my_list:
print "handling object ", name(bla) # <--- what would go instead of `name`?
# do something to bla
</code></pre>
<p><strong>Edit:</strong>... | 11 | 2009-10-08T14:54:21Z | 23,258,737 | <p>I ran into this page while wondering the same question.</p>
<p>As others have noted, it's simple enough to just grab the <code>__name__</code> attribute from a function in order to determine the name of the function. It's marginally trickier with objects that don't have a sane way to determine <code>__name__</code>... | 0 | 2014-04-24T02:29:50Z | [
"python",
"introspection"
] |
How can I get the name of an object in Python? | 1,538,342 | <p>Is there any way to get the name of an object in Python? For instance:</p>
<pre><code>my_list = [x, y, z] # x, y, z have been previously defined
for bla in my_list:
print "handling object ", name(bla) # <--- what would go instead of `name`?
# do something to bla
</code></pre>
<p><strong>Edit:</strong>... | 11 | 2009-10-08T14:54:21Z | 30,019,630 | <p>As others have mentioned, this is a really tricky question. Solutions to this are not "one size fits all", not even remotely. The difficulty (or ease) is really going to depend on your situation.</p>
<p>I have come to this problem on several occasions, but most recently while creating a debugging function. I wanted... | 1 | 2015-05-03T21:30:03Z | [
"python",
"introspection"
] |
How can I get the name of an object in Python? | 1,538,342 | <p>Is there any way to get the name of an object in Python? For instance:</p>
<pre><code>my_list = [x, y, z] # x, y, z have been previously defined
for bla in my_list:
print "handling object ", name(bla) # <--- what would go instead of `name`?
# do something to bla
</code></pre>
<p><strong>Edit:</strong>... | 11 | 2009-10-08T14:54:21Z | 30,019,808 | <p>You define a <code>class</code> and add the Unicode private function insert the <code>class</code> like</p>
<pre><code>class example:
def __init__(self, name):
self.name = name
def __unicode__(self):
return self.name
</code></pre>
<p>Of course you have to add extra variable <code>self.name</code> whic... | 0 | 2015-05-03T21:48:39Z | [
"python",
"introspection"
] |
How can I get the name of an object in Python? | 1,538,342 | <p>Is there any way to get the name of an object in Python? For instance:</p>
<pre><code>my_list = [x, y, z] # x, y, z have been previously defined
for bla in my_list:
print "handling object ", name(bla) # <--- what would go instead of `name`?
# do something to bla
</code></pre>
<p><strong>Edit:</strong>... | 11 | 2009-10-08T14:54:21Z | 39,240,374 | <p>Here is my answer, I am also using globals().items()</p>
<pre><code> def get_name_of_obj(obj, except_word = ""):
for name, item in globals().items():
if item == obj and name != except_word:
return name
</code></pre>
<p>I added except_word because I want to filter off some wo... | 1 | 2016-08-31T03:42:47Z | [
"python",
"introspection"
] |
How to sort all possible words out of a string? | 1,538,589 | <p>I'm wondering how to proceed with this task, take this string for example "thingsandstuff".</p>
<p>How could I generate all possible strings out of this string as to look them up individually against an english dictionary?</p>
<p>The goal is to find valid english words in a string that does not contain space.</p>
... | 1 | 2009-10-08T15:36:25Z | 1,538,637 | <p>The brute force approach, i.e. checking every substring, is computationally unfeasible even for strings of middling lengths (a string of length <code>N</code> has <code>O(N**2)</code> substrings). Unless there is a pretty tight bound on the length of strings you care about, that doesn't scale well.</p>
<p>To make t... | 2 | 2009-10-08T15:44:48Z | [
"python"
] |
How to sort all possible words out of a string? | 1,538,589 | <p>I'm wondering how to proceed with this task, take this string for example "thingsandstuff".</p>
<p>How could I generate all possible strings out of this string as to look them up individually against an english dictionary?</p>
<p>The goal is to find valid english words in a string that does not contain space.</p>
... | 1 | 2009-10-08T15:36:25Z | 1,538,666 | <p>Another possibility is going the other way around, instead of generating substrings from a string, grab all your candidate words and match them against your string. </p>
<p>You can store as a result (start,end) pairs of indexes of the words in the original string.</p>
<p>This could be easily done in regex, or, if ... | 5 | 2009-10-08T15:49:25Z | [
"python"
] |
How to sort all possible words out of a string? | 1,538,589 | <p>I'm wondering how to proceed with this task, take this string for example "thingsandstuff".</p>
<p>How could I generate all possible strings out of this string as to look them up individually against an english dictionary?</p>
<p>The goal is to find valid english words in a string that does not contain space.</p>
... | 1 | 2009-10-08T15:36:25Z | 1,538,687 | <p>Well here is my idea </p>
<ul>
<li>Find all possible strings containing 1 character from the original</li>
<li>Find all possible strings containing 2 characters from the original</li>
<li>... Same thing up to the length of the original string</li>
</ul>
<p>Then add all up and go match with your dictionary</p>
| 0 | 2009-10-08T15:51:53Z | [
"python"
] |
How to sort all possible words out of a string? | 1,538,589 | <p>I'm wondering how to proceed with this task, take this string for example "thingsandstuff".</p>
<p>How could I generate all possible strings out of this string as to look them up individually against an english dictionary?</p>
<p>The goal is to find valid english words in a string that does not contain space.</p>
... | 1 | 2009-10-08T15:36:25Z | 1,538,799 | <p>People talk about this as though the Order of the problem is the number of possible substrings. This is incorrect. The correct order of this problem is:</p>
<p>O( min ( number-of-words-in-dict, number-of-substring-combinations) * comparison_cost)</p>
<p>So, another approach to the problem, to build on Vinko, is... | 5 | 2009-10-08T16:06:34Z | [
"python"
] |
How to sort all possible words out of a string? | 1,538,589 | <p>I'm wondering how to proceed with this task, take this string for example "thingsandstuff".</p>
<p>How could I generate all possible strings out of this string as to look them up individually against an english dictionary?</p>
<p>The goal is to find valid english words in a string that does not contain space.</p>
... | 1 | 2009-10-08T15:36:25Z | 1,538,805 | <p>What if you break it up into syllables and then use those to construct words to compare to your dictionary. It's still a brute force method, but it would surely speed things up a bit.</p>
| 0 | 2009-10-08T16:07:27Z | [
"python"
] |
How to sort all possible words out of a string? | 1,538,589 | <p>I'm wondering how to proceed with this task, take this string for example "thingsandstuff".</p>
<p>How could I generate all possible strings out of this string as to look them up individually against an english dictionary?</p>
<p>The goal is to find valid english words in a string that does not contain space.</p>
... | 1 | 2009-10-08T15:36:25Z | 1,538,809 | <p>I looked at a powerset implementation. Too many possibilities. </p>
<p>Try encoding your string and all candidates from your dictionary and see if the candidate from the dictionary <em>could</em> be made from the candidate string. That is, do the letters in the dictionary word appear no more frequently than in your... | 0 | 2009-10-08T16:08:06Z | [
"python"
] |
How to sort all possible words out of a string? | 1,538,589 | <p>I'm wondering how to proceed with this task, take this string for example "thingsandstuff".</p>
<p>How could I generate all possible strings out of this string as to look them up individually against an english dictionary?</p>
<p>The goal is to find valid english words in a string that does not contain space.</p>
... | 1 | 2009-10-08T15:36:25Z | 1,538,836 | <p>norving wrote a great article on how to write a spell checker in python.</p>
<p><a href="http://norvig.com/spell-correct.html" rel="nofollow">http://norvig.com/spell-correct.html</a></p>
<p>it will give you an good idea on how to detect words. (i.e. just go testing each group of chars until you get a valid word...... | 1 | 2009-10-08T16:12:19Z | [
"python"
] |
How to sort all possible words out of a string? | 1,538,589 | <p>I'm wondering how to proceed with this task, take this string for example "thingsandstuff".</p>
<p>How could I generate all possible strings out of this string as to look them up individually against an english dictionary?</p>
<p>The goal is to find valid english words in a string that does not contain space.</p>
... | 1 | 2009-10-08T15:36:25Z | 1,539,056 | <p>Take a look to <a href="http://translate.google.es/translate?u=http%3A%2F%2Ffortran.blogspot.com%2F2008%2F07%2Fel-melenas-de-cifras-y-letras-no-tena.html&sl=es&tl=en&hl=es&ie=UTF-8" rel="nofollow">this post</a>, it addresses the same problem, both in Python and OCaml, with a solution based in normali... | 0 | 2009-10-08T16:44:30Z | [
"python"
] |
How to sort all possible words out of a string? | 1,538,589 | <p>I'm wondering how to proceed with this task, take this string for example "thingsandstuff".</p>
<p>How could I generate all possible strings out of this string as to look them up individually against an english dictionary?</p>
<p>The goal is to find valid english words in a string that does not contain space.</p>
... | 1 | 2009-10-08T15:36:25Z | 1,539,119 | <p>Code:</p>
<pre><code>def all_substrings(val):
return [val[start:end] for start in range(len(val)) for end in range(start + 1, len(val))]
val = "thingsandstuff"
for result in all_substrings(val):
print result
</code></pre>
<p>Output:</p>
<pre><code>t
th
thi
thin
thing
</code></pre>
<p>[ ... ]</p>
<pre><... | 0 | 2009-10-08T16:54:10Z | [
"python"
] |
How to sort all possible words out of a string? | 1,538,589 | <p>I'm wondering how to proceed with this task, take this string for example "thingsandstuff".</p>
<p>How could I generate all possible strings out of this string as to look them up individually against an english dictionary?</p>
<p>The goal is to find valid english words in a string that does not contain space.</p>
... | 1 | 2009-10-08T15:36:25Z | 1,539,332 | <p>This will find whether or not a candidate can be formed out of the letters in a given word; it's assumed that <code>word</code> (but not <code>candidate</code>) is sorted prior to the call.</p>
<pre><code>>>> def match(candidate, word):
def next_char(w):
for ch in sorted(w):
... | 1 | 2009-10-08T17:32:27Z | [
"python"
] |
How to sort all possible words out of a string? | 1,538,589 | <p>I'm wondering how to proceed with this task, take this string for example "thingsandstuff".</p>
<p>How could I generate all possible strings out of this string as to look them up individually against an english dictionary?</p>
<p>The goal is to find valid english words in a string that does not contain space.</p>
... | 1 | 2009-10-08T15:36:25Z | 1,539,336 | <p>If you know the full dictionary well in advance, and it doesn't change between searches, you might try the following...</p>
<p>Index the dictionary. Each word (e.g. "hello") becomes a (key, data) tuple such as ("ehllo", "hello"). In the key, the letters are sorted alphabetically.</p>
<p>Good index data structures ... | 0 | 2009-10-08T17:32:49Z | [
"python"
] |
HTTP Download very Big File | 1,538,617 | <p>I'm working at a web application in Python/Twisted.</p>
<p>I want the user to be able to download a very big file (> 100 Mb). I don't want to load all the file in memory (of the server), of course.</p>
<p>server side I have this idea:</p>
<pre><code>...
request.setHeader('Content-Type', 'text/plain')
fp = open(fi... | 12 | 2009-10-08T15:43:00Z | 1,538,647 | <p>Yes, the Content-Length header will give you the progress bar you desire!</p>
| 3 | 2009-10-08T15:45:34Z | [
"python",
"http",
"download",
"twisted"
] |
HTTP Download very Big File | 1,538,617 | <p>I'm working at a web application in Python/Twisted.</p>
<p>I want the user to be able to download a very big file (> 100 Mb). I don't want to load all the file in memory (of the server), of course.</p>
<p>server side I have this idea:</p>
<pre><code>...
request.setHeader('Content-Type', 'text/plain')
fp = open(fi... | 12 | 2009-10-08T15:43:00Z | 1,545,148 | <p>If this really is <code>text/plain</code> content, you should seriously consider sending it with <code>Content-Encoding: gzip</code> whenever a client indicates they can handle it. You ought to see huge bandwidth savings. Additionally, if this is a static file, what you really want to do is use <code>sendfile(2)</... | 3 | 2009-10-09T17:43:54Z | [
"python",
"http",
"download",
"twisted"
] |
HTTP Download very Big File | 1,538,617 | <p>I'm working at a web application in Python/Twisted.</p>
<p>I want the user to be able to download a very big file (> 100 Mb). I don't want to load all the file in memory (of the server), of course.</p>
<p>server side I have this idea:</p>
<pre><code>...
request.setHeader('Content-Type', 'text/plain')
fp = open(fi... | 12 | 2009-10-08T15:43:00Z | 1,657,324 | <p>Two big problems with the sample code you posted are that it is non-cooperative and it loads the entire file into memory before sending it.</p>
<pre><code>while r != '':
r = fp.read(1024)
request.write(r)
</code></pre>
<p>Remember that Twisted uses cooperative multitasking to achieve any sort of concurrenc... | 31 | 2009-11-01T14:37:00Z | [
"python",
"http",
"download",
"twisted"
] |
HTTP Download very Big File | 1,538,617 | <p>I'm working at a web application in Python/Twisted.</p>
<p>I want the user to be able to download a very big file (> 100 Mb). I don't want to load all the file in memory (of the server), of course.</p>
<p>server side I have this idea:</p>
<pre><code>...
request.setHeader('Content-Type', 'text/plain')
fp = open(fi... | 12 | 2009-10-08T15:43:00Z | 8,377,700 | <p>Here is an example of downloading files in chunks using urllib2, which you could use from inside of a twisted function call</p>
<pre><code>import os
import urllib2
import math
def downloadChunks(url):
"""Helper to download large files
the only arg is a url
this file will go to a temp directory
... | 0 | 2011-12-04T18:49:32Z | [
"python",
"http",
"download",
"twisted"
] |
Why are python strings and tuples are made immutable? | 1,538,663 | <p>I am not sure why strings and tuples were made to be immutable; what are the advantages and disadvantage of making them immutable?</p>
| 37 | 2009-10-08T15:48:57Z | 1,538,685 | <blockquote>
<p>One is performance: knowing that a
string is immutable makes it easy to
lay it out at construction time â
fixed and unchanging storage
requirements. This is also one of the
reasons for the distinction between
tuples and lists. This also allows the
implementation to safely reuse string
... | 25 | 2009-10-08T15:51:29Z | [
"python",
"string",
"immutability",
"tuples"
] |
Why are python strings and tuples are made immutable? | 1,538,663 | <p>I am not sure why strings and tuples were made to be immutable; what are the advantages and disadvantage of making them immutable?</p>
| 37 | 2009-10-08T15:48:57Z | 1,538,686 | <p>pros: Performance </p>
<p>cons: you can't change mutables.</p>
| 2 | 2009-10-08T15:51:34Z | [
"python",
"string",
"immutability",
"tuples"
] |
Why are python strings and tuples are made immutable? | 1,538,663 | <p>I am not sure why strings and tuples were made to be immutable; what are the advantages and disadvantage of making them immutable?</p>
| 37 | 2009-10-08T15:48:57Z | 1,538,689 | <p>One big advantage of making them immutable is that they can be used as keys in a dictionary. I'm sure the internal data structures used by dictionaries would get quite messed up if the keys were allowed to change.</p>
| 10 | 2009-10-08T15:52:09Z | [
"python",
"string",
"immutability",
"tuples"
] |
Why are python strings and tuples are made immutable? | 1,538,663 | <p>I am not sure why strings and tuples were made to be immutable; what are the advantages and disadvantage of making them immutable?</p>
| 37 | 2009-10-08T15:48:57Z | 1,632,939 | <p>Imagine a language called FakeMutablePython, where you can alter strings using list assignment and such (such as <code>mystr[0] = 'a'</code>)</p>
<pre><code>a = "abc"
</code></pre>
<p>That creates an entry in memory in memory address 0x1, containing "abc", and the identifier <code>a</code> pointing to it.</p>
<p>... | 61 | 2009-10-27T18:56:17Z | [
"python",
"string",
"immutability",
"tuples"
] |
Why are python strings and tuples are made immutable? | 1,538,663 | <p>I am not sure why strings and tuples were made to be immutable; what are the advantages and disadvantage of making them immutable?</p>
| 37 | 2009-10-08T15:48:57Z | 3,165,540 | <p>Immutable types are conceptually much simpler than mutable ones. For example, you don't have to mess with copy constructors or const-correctness like in C++. The more types are immutable, the easier the language gets. Thus the easiest languages are the pure functional ones without any global state (because lambda ca... | 3 | 2010-07-02T12:16:34Z | [
"python",
"string",
"immutability",
"tuples"
] |
Why are python strings and tuples are made immutable? | 1,538,663 | <p>I am not sure why strings and tuples were made to be immutable; what are the advantages and disadvantage of making them immutable?</p>
| 37 | 2009-10-08T15:48:57Z | 10,837,060 | <p>Perl has mutable strings and seems to function just fine. The above seems like a lot of hand waving and rationalization for an arbitrary design decision.</p>
<p>My answer to the question of why Python has immutable strings, because Python creator Guido van Rossum wanted it that way and he now has legions of fans t... | 3 | 2012-05-31T15:54:11Z | [
"python",
"string",
"immutability",
"tuples"
] |
can't import gdal in python? | 1,538,725 | <p>I have <code>gdal</code> installed and running on Ubuntu Jaunty but I can't run <code>gdal2tiles</code> because I get the error:</p>
<pre><code>Traceback (most recent call last):
File "/usr/local/bin/gdal2tiles.py", line 42, in <module>
import gdal
ImportError: No module named gdal
</code></pre>
<p>Whe... | 9 | 2009-10-08T15:56:25Z | 1,538,763 | <p>Ith seems to be a "<strong><em>Python Path</em></strong>" issue. Python libraries are looked-up within a defined path. Try</p>
<pre><code>import sys
sys.path
</code></pre>
<p>If the directory where the gdal.py and related files is not in this list, then Python cannot find it. That's for the "diagnostics" pa... | 14 | 2009-10-08T16:02:01Z | [
"python",
"gdal"
] |
can't import gdal in python? | 1,538,725 | <p>I have <code>gdal</code> installed and running on Ubuntu Jaunty but I can't run <code>gdal2tiles</code> because I get the error:</p>
<pre><code>Traceback (most recent call last):
File "/usr/local/bin/gdal2tiles.py", line 42, in <module>
import gdal
ImportError: No module named gdal
</code></pre>
<p>Whe... | 9 | 2009-10-08T15:56:25Z | 1,538,803 | <p>Here is a link that teaches how to install and use Python + GDAL, OGR and other tools.</p>
<p>I hope its useful.</p>
<p><a href="http://www.gis.usu.edu/~chrisg/python/2009/">http://www.gis.usu.edu/~chrisg/python/2009/</a></p>
| 6 | 2009-10-08T16:07:17Z | [
"python",
"gdal"
] |
can't import gdal in python? | 1,538,725 | <p>I have <code>gdal</code> installed and running on Ubuntu Jaunty but I can't run <code>gdal2tiles</code> because I get the error:</p>
<pre><code>Traceback (most recent call last):
File "/usr/local/bin/gdal2tiles.py", line 42, in <module>
import gdal
ImportError: No module named gdal
</code></pre>
<p>Whe... | 9 | 2009-10-08T15:56:25Z | 2,118,630 | <p>You may also want to check GDAL Wiki dedicated to the bindings to Python - <a href="http://trac.osgeo.org/gdal/wiki/GdalOgrInPython" rel="nofollow">GdalOgrInPython</a> where the installation and usage on Linux and Windows platforms is discussed.</p>
| 1 | 2010-01-22T16:15:48Z | [
"python",
"gdal"
] |
Is the single underscore "_" a built-in variable in Python? | 1,538,832 | <p>I don't understand what this single underscore means. Is it a magic variable? I can't see it in locals() and globals().</p>
<pre><code>>>> 'abc'
'abc'
>>> len(_)
3
>>>
</code></pre>
| 26 | 2009-10-08T16:11:33Z | 1,538,868 | <p>In the standard Python REPL, <code>_</code> represents the last returned value -- at the point where you called <code>len(_)</code>, <code>_</code> was the value <code>'abc'</code>.</p>
<p>For example:</p>
<pre><code>>>> 10
10
>>> _
10
>>> _ + 5
15
>>> _ + 5
20
</code></pre>
<p... | 39 | 2009-10-08T16:16:42Z | [
"python"
] |
Is the single underscore "_" a built-in variable in Python? | 1,538,832 | <p>I don't understand what this single underscore means. Is it a magic variable? I can't see it in locals() and globals().</p>
<pre><code>>>> 'abc'
'abc'
>>> len(_)
3
>>>
</code></pre>
| 26 | 2009-10-08T16:11:33Z | 1,538,917 | <p>Why you can't see it? It is in <code>__builtins__</code></p>
<pre><code>>>> __builtins__._ is _
True
</code></pre>
<p>So it's neither global nor local. <sup>1</sup></p>
<p>And where does this assignment happen? <code>sys.displayhook</code>:</p>
<pre><code>>>> import sys
>>> help(sys.di... | 15 | 2009-10-08T16:23:16Z | [
"python"
] |
Is the single underscore "_" a built-in variable in Python? | 1,538,832 | <p>I don't understand what this single underscore means. Is it a magic variable? I can't see it in locals() and globals().</p>
<pre><code>>>> 'abc'
'abc'
>>> len(_)
3
>>>
</code></pre>
| 26 | 2009-10-08T16:11:33Z | 1,538,942 | <p>Usually, we are using _ in Python to bind a ugettext function.</p>
| 2 | 2009-10-08T16:26:45Z | [
"python"
] |
Caesar's Cipher using python, could use a little help | 1,538,935 | <p>I'm trying to make a "Caesar's Cipher" while using python..this is what I have so far. Could anyone tell me how this is looking? Am I going in the right direction? What am I missing? When I run the program to say for example (josh is cool) I don't get the cipher on the same line. It looks like this when I do <code>m... | 2 | 2009-10-08T16:25:51Z | 1,539,046 | <p>Put a comma after each print statement; it will still put a space between the characters, but they'll all be on the same line. If you need to print them without the spaces, build them all into a single string and print that at the end.</p>
| 1 | 2009-10-08T16:43:45Z | [
"python"
] |
Caesar's Cipher using python, could use a little help | 1,538,935 | <p>I'm trying to make a "Caesar's Cipher" while using python..this is what I have so far. Could anyone tell me how this is looking? Am I going in the right direction? What am I missing? When I run the program to say for example (josh is cool) I don't get the cipher on the same line. It looks like this when I do <code>m... | 2 | 2009-10-08T16:25:51Z | 1,539,075 | <p>Barring the syntax errors, your code seems to work.</p>
<p>However, I took the liberty of removing all duplicates, and cleaning it up:</p>
<pre><code>first = raw_input("Please enter Plaintext to Cipher: ")
k = int(raw_input("Please enter the shift: "))
result = ''
for second in first:
x=ord(second)
x=x+k
... | 0 | 2009-10-08T16:47:38Z | [
"python"
] |
Caesar's Cipher using python, could use a little help | 1,538,935 | <p>I'm trying to make a "Caesar's Cipher" while using python..this is what I have so far. Could anyone tell me how this is looking? Am I going in the right direction? What am I missing? When I run the program to say for example (josh is cool) I don't get the cipher on the same line. It looks like this when I do <code>m... | 2 | 2009-10-08T16:25:51Z | 1,539,324 | <p>This code should work pretty well. It also handles arbitrary offsets, including negative.</p>
<pre><code>phrase = raw_input("Please enter plaintext to Cipher: ")
shift = int(raw_input("Please enter shift: "))
result = ''
for char in phrase:
x = ord(char)
if char.isalpha():
x = x + shift
... | 2 | 2009-10-08T17:31:45Z | [
"python"
] |
Caesar's Cipher using python, could use a little help | 1,538,935 | <p>I'm trying to make a "Caesar's Cipher" while using python..this is what I have so far. Could anyone tell me how this is looking? Am I going in the right direction? What am I missing? When I run the program to say for example (josh is cool) I don't get the cipher on the same line. It looks like this when I do <code>m... | 2 | 2009-10-08T16:25:51Z | 1,539,611 | <p>Here is a different method to show how we can handle this in a very clean way. We define an input alphabet and an output alphabet, then a translation table and use <code>unicode.translate()</code> to do the actual encryption.</p>
<pre><code>import string
# Blatantly steal Lennart's UI design
first = unicode(raw_inp... | 1 | 2009-10-08T18:22:52Z | [
"python"
] |
Caesar's Cipher using python, could use a little help | 1,538,935 | <p>I'm trying to make a "Caesar's Cipher" while using python..this is what I have so far. Could anyone tell me how this is looking? Am I going in the right direction? What am I missing? When I run the program to say for example (josh is cool) I don't get the cipher on the same line. It looks like this when I do <code>m... | 2 | 2009-10-08T16:25:51Z | 4,987,512 | <p>I like kaizer.se's answer, but I think I can simplify it using the <a href="http://docs.python.org/library/string.html#string.maketrans" rel="nofollow">string.maketrans</a> function:</p>
<pre><code>import string
first = raw_input("Please enter Plaintext to Cipher: ")
k = int(raw_input("Please enter the shift: "))
... | 6 | 2011-02-13T23:02:53Z | [
"python"
] |
Caesar's Cipher using python, could use a little help | 1,538,935 | <p>I'm trying to make a "Caesar's Cipher" while using python..this is what I have so far. Could anyone tell me how this is looking? Am I going in the right direction? What am I missing? When I run the program to say for example (josh is cool) I don't get the cipher on the same line. It looks like this when I do <code>m... | 2 | 2009-10-08T16:25:51Z | 17,640,644 | <p>I very simple, 3-shift solution without Umlauts and alike would be:</p>
<pre><code>def caesar(inputstring):
shifted=string.lowercase[3:]+string.lowercase[:3]
return "".join(shifted[string.lowercase.index(letter)] for letter in inputstring)
</code></pre>
<p>and reverse:</p>
<pre><code>def brutus(inputstrin... | 0 | 2013-07-14T15:12:01Z | [
"python"
] |
Caesar's Cipher using python, could use a little help | 1,538,935 | <p>I'm trying to make a "Caesar's Cipher" while using python..this is what I have so far. Could anyone tell me how this is looking? Am I going in the right direction? What am I missing? When I run the program to say for example (josh is cool) I don't get the cipher on the same line. It looks like this when I do <code>m... | 2 | 2009-10-08T16:25:51Z | 20,006,751 | <p>For Python 3.3, try using the ord(), chr() and .isalpha functions:</p>
<pre><code>m = input("What is your message?: ")
s = int(input("What is the shift?: "))
for i in m:
if i.isalpha():
if (ord(i)+s)>90:
print(chr(ord(i)+s-26),end=""),
elif chr(ord(i)+s-26)<65:
prin... | 0 | 2013-11-15T17:12:16Z | [
"python"
] |
Caesar's Cipher using python, could use a little help | 1,538,935 | <p>I'm trying to make a "Caesar's Cipher" while using python..this is what I have so far. Could anyone tell me how this is looking? Am I going in the right direction? What am I missing? When I run the program to say for example (josh is cool) I don't get the cipher on the same line. It looks like this when I do <code>m... | 2 | 2009-10-08T16:25:51Z | 25,827,384 | <p>Here is a oneliner.</p>
<pre><code>>>> brutus=lambda message,cipher,direction:''.join([chr((ord(letter)+(cipher*direction))%256) for letter in message])
>>> encrypted= brutus('Message to be encrypted',14,1) #direction=1 for encryption
>>> encrypted
'[s\x81\x81ous.\x82}.ps.s|q\x80\x87~\x82... | 0 | 2014-09-13T20:28:34Z | [
"python"
] |
Perform an action and redirecting to the same URL doesn't refresh the page | 1,538,994 | <p>We are working on a new web site using Apache, Python and Django.</p>
<p>In the development phase, no problem but once binding to Apache, using Firefox 3.5.3, we got a strange problem.</p>
<p>We stand on :</p>
<p><a href="http://website.fr/search/" rel="nofollow">http://website.fr/search/</a></p>
<p>When we want... | 2 | 2009-10-08T16:35:31Z | 1,539,326 | <p>How about redirecting to</p>
<pre><code>http://website.fr/search/?ignoredvar=<random int>
</code></pre>
<p>Please provide the full http conversation If you need a better solution.
The conversation can be traced using firebug or live http headers.</p>
<p>Btw. The above solution is the only one I know for sim... | 0 | 2009-10-08T17:32:04Z | [
"python",
"django",
"http",
"httpwebrequest",
"http-status-code-302"
] |
Perform an action and redirecting to the same URL doesn't refresh the page | 1,538,994 | <p>We are working on a new web site using Apache, Python and Django.</p>
<p>In the development phase, no problem but once binding to Apache, using Firefox 3.5.3, we got a strange problem.</p>
<p>We stand on :</p>
<p><a href="http://website.fr/search/" rel="nofollow">http://website.fr/search/</a></p>
<p>When we want... | 2 | 2009-10-08T16:35:31Z | 1,558,399 | <p>I'd say you're doing it wrong. The same URL should be the same page. Everything with HTTP and web browsers assume this, and when you don't follow this convention you're going to get yourself into trouble. Just add the search parameters and sort orders as query parameters to the URL.</p>
| 1 | 2009-10-13T05:52:43Z | [
"python",
"django",
"http",
"httpwebrequest",
"http-status-code-302"
] |
Perform an action and redirecting to the same URL doesn't refresh the page | 1,538,994 | <p>We are working on a new web site using Apache, Python and Django.</p>
<p>In the development phase, no problem but once binding to Apache, using Firefox 3.5.3, we got a strange problem.</p>
<p>We stand on :</p>
<p><a href="http://website.fr/search/" rel="nofollow">http://website.fr/search/</a></p>
<p>When we want... | 2 | 2009-10-08T16:35:31Z | 1,560,646 | <p>What happens is, the browser asks for the new URL and via 302 gets redirected back to the previous one, which is in the cache and thus not refreshed. Adding a random integer, like Piotr is suggesting will solve the problem. For randomness you can use simple timestamp.</p>
<p>Implication of performing forward as you... | 3 | 2009-10-13T14:38:54Z | [
"python",
"django",
"http",
"httpwebrequest",
"http-status-code-302"
] |
Using Python's xml.dom.minidom | 1,539,023 | <p>I'm trying to use Python's xml.dom.minidom, and I'm getting the following error:</p>
<pre><code>>>> from xml.dom import minidom
>>> xdocument = minidom.Document()
>>> xrss = minidom.Element("rss")
>>> xdocument.appendChild(xrss)
<DOM Element: rss at 0xc1d0f8>
>>> x... | 2 | 2009-10-08T16:39:20Z | 1,539,085 | <p>Use <code>xdocument.createElement('name')</code> to create new elements. This is the standard way to do that in DOM.</p>
| 3 | 2009-10-08T16:48:33Z | [
"python",
"xml"
] |
Using Python's xml.dom.minidom | 1,539,023 | <p>I'm trying to use Python's xml.dom.minidom, and I'm getting the following error:</p>
<pre><code>>>> from xml.dom import minidom
>>> xdocument = minidom.Document()
>>> xrss = minidom.Element("rss")
>>> xdocument.appendChild(xrss)
<DOM Element: rss at 0xc1d0f8>
>>> x... | 2 | 2009-10-08T16:39:20Z | 1,539,122 | <p>Replace <code>xdocument.appendChild(xrss)</code> with <code>xrss = xdocument.appendChild(xrss)</code>. From the <a href="http://docs.python.org/library/xml.dom.html#xml.dom.Node.appendChild" rel="nofollow">docs</a>:</p>
<blockquote>
<p>Node.appendChild(newChild) Add a new
child node to this node at the end of
... | 0 | 2009-10-08T16:54:33Z | [
"python",
"xml"
] |
Weird behaviour with two Trac instances under Apache + mod_wsgi | 1,539,203 | <p>I am trying to configure two Trac instances in order to access them via browser each one with a different url:</p>
<pre><code>http://trac.domain.com/trac1
http://trac.domain.com/trac2
</code></pre>
<p>First time I access them Apache response is fine, I get the first Trac with /trac1, then the second one in /trac2.... | 2 | 2009-10-08T17:09:19Z | 1,539,232 | <p>Move your egg cache to separate dirs</p>
<p>trac1.wsgi:</p>
<pre><code>import os
os.environ['TRAC_ENV'] = '/home/myuser/trac/trac1'
os.environ['PYTHON_EGG_CACHE'] = '/tmp/trac1'
import trac.web.main
application = trac.web.main.dispatch_request
</code></pre>
<p>trac2.wsgi:</p>
<pre><code>import os
os.environ... | 0 | 2009-10-08T17:15:21Z | [
"python",
"apache",
"trac",
"mod-wsgi"
] |
Weird behaviour with two Trac instances under Apache + mod_wsgi | 1,539,203 | <p>I am trying to configure two Trac instances in order to access them via browser each one with a different url:</p>
<pre><code>http://trac.domain.com/trac1
http://trac.domain.com/trac2
</code></pre>
<p>First time I access them Apache response is fine, I get the first Trac with /trac1, then the second one in /trac2.... | 2 | 2009-10-08T17:09:19Z | 1,539,691 | <p>I found the solution myself, it was on the Trac documentation ("important note" section), and I did not event take look, fool of me :P</p>
<p><a href="http://trac.edgewall.org/wiki/TracModWSGI" rel="nofollow">http://trac.edgewall.org/wiki/TracModWSGI</a></p>
| 2 | 2009-10-08T18:40:17Z | [
"python",
"apache",
"trac",
"mod-wsgi"
] |
Python client library for WebDAV | 1,539,378 | <p>I'd like to implement a piece of functionality in my application that uploads and manipulates files on a WebDAV server. I'm looking for a mature Python library that would give an interface similar to the <code>os.*</code> modules for working with the remote files. Googling has turned up a smattering of options for W... | 22 | 2009-10-08T17:38:32Z | 1,541,478 | <p>I don't know of any specifically but, depending on your platform, it may be simpler to mount and access the WebDAV-served files through the file system. There's <a href="http://en.wikipedia.org/wiki/Davfs2" rel="nofollow">davfs2</a> out there and some OS's, like Mac OS X, have WebDAV file system support built in.</... | 2 | 2009-10-09T02:00:54Z | [
"python",
"client",
"webdav"
] |
Python client library for WebDAV | 1,539,378 | <p>I'd like to implement a piece of functionality in my application that uploads and manipulates files on a WebDAV server. I'm looking for a mature Python library that would give an interface similar to the <code>os.*</code> modules for working with the remote files. Googling has turned up a smattering of options for W... | 22 | 2009-10-08T17:38:32Z | 1,541,509 | <p>I have no experience with any of these libraries, but the Python Package Index ("PyPi") <a href="http://pypi.python.org/pypi?%3Aaction=search&term=webdav&submit=search" rel="nofollow">lists quite a few webdav modules</a>.</p>
| 0 | 2009-10-09T02:16:07Z | [
"python",
"client",
"webdav"
] |
Python client library for WebDAV | 1,539,378 | <p>I'd like to implement a piece of functionality in my application that uploads and manipulates files on a WebDAV server. I'm looking for a mature Python library that would give an interface similar to the <code>os.*</code> modules for working with the remote files. Googling has turned up a smattering of options for W... | 22 | 2009-10-08T17:38:32Z | 1,545,266 | <p>Apparently you're looking for a WebDAV client library.</p>
<p>Not sure how the gazillion hits came up, it seems the following 2 looks relevant:</p>
<ul>
<li>PyDAV:
<a href="http://users.sfo.com/~jdavis/Software/PyDAV/readme.html#client" rel="nofollow">http://users.sfo.com/~jdavis/Software/PyDAV/readme.html#client<... | 1 | 2009-10-09T18:06:36Z | [
"python",
"client",
"webdav"
] |
Python client library for WebDAV | 1,539,378 | <p>I'd like to implement a piece of functionality in my application that uploads and manipulates files on a WebDAV server. I'm looking for a mature Python library that would give an interface similar to the <code>os.*</code> modules for working with the remote files. Googling has turned up a smattering of options for W... | 22 | 2009-10-08T17:38:32Z | 6,898,536 | <p>I just had a similar need and ended up testing a few Python WebDAV clients for my needs (uploading and downloading files from a WebDAV server). Here's a summary of my experience:</p>
<p>1) The one that worked for me is <a href="https://launchpad.net/python-webdav-lib">python-webdav-lib</a>.</p>
<p>Not much documen... | 9 | 2011-08-01T12:39:09Z | [
"python",
"client",
"webdav"
] |
Python client library for WebDAV | 1,539,378 | <p>I'd like to implement a piece of functionality in my application that uploads and manipulates files on a WebDAV server. I'm looking for a mature Python library that would give an interface similar to the <code>os.*</code> modules for working with the remote files. Googling has turned up a smattering of options for W... | 22 | 2009-10-08T17:38:32Z | 12,193,865 | <p>It's sad that for this question ("What Python webdav library to use?"), which for sure interests more than one person, unrelated answer was accepted ("don't use Python webdav library"). Well, common problem on Stackexchange.</p>
<p>For people who will be looking for real answers, and given the requirements in the o... | 38 | 2012-08-30T09:32:22Z | [
"python",
"client",
"webdav"
] |
Python client library for WebDAV | 1,539,378 | <p>I'd like to implement a piece of functionality in my application that uploads and manipulates files on a WebDAV server. I'm looking for a mature Python library that would give an interface similar to the <code>os.*</code> modules for working with the remote files. Googling has turned up a smattering of options for W... | 22 | 2009-10-08T17:38:32Z | 23,611,950 | <pre><code>import easywebdav
webdav = easywebdav.connect(
host='dav.dumptruck.goldenfrog.com',
username='_snip_',
port=443,
protocol="https",
password='_snip_')
_file = "test.py"
print webdav.cd("/dav/")
# print webdav._get_url("")
# print webdav.ls()
# print webdav.exists("/dav/test.py")
# print... | 2 | 2014-05-12T14:37:48Z | [
"python",
"client",
"webdav"
] |
Python client library for WebDAV | 1,539,378 | <p>I'd like to implement a piece of functionality in my application that uploads and manipulates files on a WebDAV server. I'm looking for a mature Python library that would give an interface similar to the <code>os.*</code> modules for working with the remote files. Googling has turned up a smattering of options for W... | 22 | 2009-10-08T17:38:32Z | 26,562,880 | <p>Install:</p>
<pre><code>$ sudo apt-get install libxml2-dev libxslt-dev python-dev
$ sudo apt-get install libcurl4-openssl-dev python-pycurl
$ sudo easy_install webdavclient
</code></pre>
<p>Examples:</p>
<pre><code>import webdav.client as wc
options = {
'webdav_hostname': "https://webdav.server.ru",
'webdav_... | 0 | 2014-10-25T13:26:19Z | [
"python",
"client",
"webdav"
] |
Django Reuseable Apps | 1,539,485 | <p>I came across many resources about the difference between Django projects and reusable apps, most prominently the <a href="http://www.youtube.com/watch?v=A-S0tqpPga4" rel="nofollow">DjangoCon talk</a>, and <a href="http://pinaxproject.com/" rel="nofollow">Pinax Project</a>.</p>
<p>However, being a newbie, writing m... | 2 | 2009-10-08T17:59:07Z | 1,539,732 | <p>James Bennett's <a href="http://rads.stackoverflow.com/amzn/click/1430219386" rel="nofollow">Practical Django Projects</a> does a pretty good job of covering those topics in general and even includes a chapter specifically on "Writing Reusable Django Applications" that goes through an example of splitting one of the... | 4 | 2009-10-08T18:48:24Z | [
"python",
"django",
"django-apps"
] |
Django Reuseable Apps | 1,539,485 | <p>I came across many resources about the difference between Django projects and reusable apps, most prominently the <a href="http://www.youtube.com/watch?v=A-S0tqpPga4" rel="nofollow">DjangoCon talk</a>, and <a href="http://pinaxproject.com/" rel="nofollow">Pinax Project</a>.</p>
<p>However, being a newbie, writing m... | 2 | 2009-10-08T17:59:07Z | 1,540,299 | <p>You can watch video (DjangoCon 2008: Reusable Apps) - <a href="http://www.youtube.com/watch?v=A-S0tqpPga4" rel="nofollow">http://www.youtube.com/watch?v=A-S0tqpPga4</a> and get the idea, how to use it.</p>
<p>There are a lot of reusapbe apps at Google, djangosnippets, git, etc. Most popular:</p>
<ul>
<li>django-co... | 3 | 2009-10-08T20:39:26Z | [
"python",
"django",
"django-apps"
] |
Django Reuseable Apps | 1,539,485 | <p>I came across many resources about the difference between Django projects and reusable apps, most prominently the <a href="http://www.youtube.com/watch?v=A-S0tqpPga4" rel="nofollow">DjangoCon talk</a>, and <a href="http://pinaxproject.com/" rel="nofollow">Pinax Project</a>.</p>
<p>However, being a newbie, writing m... | 2 | 2009-10-08T17:59:07Z | 1,544,591 | <p>If you want to see "sample projects with reusable apps interacting with each other," there's no better place to go than downloading <a href="http://pinaxproject.com" rel="nofollow">Pinax</a>, cloning one of their sample projects (just follow the docs) and reading through the code carefully.</p>
| 3 | 2009-10-09T15:43:45Z | [
"python",
"django",
"django-apps"
] |
Changing document's attributes in Python's xml.dom.minidom | 1,539,555 | <p>I created a <code>xml.dom.minidom.Document</code>.</p>
<p>How do I give it attributes so that when I do <code>.toprettyxml()</code> it will show like this:</p>
<p><code><?xml version="1.0" encoding="iso-8859-2"?></code></p>
| 0 | 2009-10-08T18:09:28Z | 1,539,569 | <p><code>.toprettyxml()</code> has an encoding keyword argument:</p>
<pre><code>Document.toprettyxml(self, indent='\t', newl='\n', encoding=None)
</code></pre>
| 1 | 2009-10-08T18:14:04Z | [
"python",
"xml"
] |
Determine which Button was pressed in Tkinter? | 1,539,787 | <p>I'm making a simple little utility while learning Python. It dynamically generates a list of buttons:</p>
<pre><code>for method in methods:
button = Button(self.methodFrame, text=method, command=self.populateMethod)
button.pack({'fill': 'x', 'expand': 1, 'padx': 5, 'pady': 3})
</code></pre>
<p>That part w... | 6 | 2009-10-08T18:59:23Z | 1,539,868 | <p>It seems that the command method is not passed any event object.</p>
<p>I can think of two workarounds:</p>
<ul>
<li><p>associate a unique callback to each button</p></li>
<li><p>call <code>button.bind('<Button-1>', self.populateMethod)</code> instead of passing self.populateMethod as <code>command</code>. s... | 1 | 2009-10-08T19:15:08Z | [
"python",
"button",
"tkinter"
] |
Determine which Button was pressed in Tkinter? | 1,539,787 | <p>I'm making a simple little utility while learning Python. It dynamically generates a list of buttons:</p>
<pre><code>for method in methods:
button = Button(self.methodFrame, text=method, command=self.populateMethod)
button.pack({'fill': 'x', 'expand': 1, 'padx': 5, 'pady': 3})
</code></pre>
<p>That part w... | 6 | 2009-10-08T18:59:23Z | 1,543,336 | <p>You can use lambda to pass arguments to a command:</p>
<pre><code>def populateMethod(self, method):
print "method:", method
for method in ["one","two","three"]:
button = Button(self.methodFrame, text=method,
command=lambda m=method: self.populateMethod(m))
button.pack({'fill': 'x', 'expand': 1... | 11 | 2009-10-09T11:51:46Z | [
"python",
"button",
"tkinter"
] |
Python HTTP server with XML-RPC | 1,540,011 | <p>I have a server that has to respond to HTTP and XML-RPC requests. Right now I have an instance of SimpleXMLRPCServer, and an instance of BaseHTTPServer.HTTPServer with a custom request handler, running on different ports. I'd like to run both services on a single port. </p>
<p>I think it should be possible to modif... | 0 | 2009-10-08T19:45:52Z | 1,540,053 | <p>Is there a reason not to run a real webserver out front with url rewrites to the two ports you are usign now? It's going to make life much easier in the long run</p>
| 0 | 2009-10-08T19:55:17Z | [
"python",
"http",
"xml-rpc"
] |
Python HTTP server with XML-RPC | 1,540,011 | <p>I have a server that has to respond to HTTP and XML-RPC requests. Right now I have an instance of SimpleXMLRPCServer, and an instance of BaseHTTPServer.HTTPServer with a custom request handler, running on different ports. I'd like to run both services on a single port. </p>
<p>I think it should be possible to modif... | 0 | 2009-10-08T19:45:52Z | 1,543,370 | <p>Use <code>SimpleXMLRPCDispatcher</code> class directly from your own request handler.</p>
| 0 | 2009-10-09T11:59:43Z | [
"python",
"http",
"xml-rpc"
] |
Python HTTP server with XML-RPC | 1,540,011 | <p>I have a server that has to respond to HTTP and XML-RPC requests. Right now I have an instance of SimpleXMLRPCServer, and an instance of BaseHTTPServer.HTTPServer with a custom request handler, running on different ports. I'd like to run both services on a single port. </p>
<p>I think it should be possible to modif... | 0 | 2009-10-08T19:45:52Z | 21,441,674 | <p>Simplest way would be (tested for Python 3.3 but should work for 2.x with modified imports):</p>
<pre><code>from http.server import SimpleHTTPRequestHandler
from xmlrpc.server import SimpleXMLRPCRequestHandler,SimpleXMLRPCServer
class MixRequestHandler(SimpleHTTPRequestHandler,SimpleXMLRPCRequestHandler):
pass... | 0 | 2014-01-29T20:15:01Z | [
"python",
"http",
"xml-rpc"
] |
Replace values in list using Python | 1,540,049 | <p>I have a list where I want to replace values with None where condition() returns True.</p>
<pre><code>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
</code></pre>
<p>For example, if condition checks bool(item%2) should return:</p>
<pre><code>[None, 1, None, 3, None, 5, None, 7, None, 9, None]
</code></pre>
<p>What is the mo... | 59 | 2009-10-08T19:54:18Z | 1,540,060 | <pre><code>>>> L = range (11)
>>> [ x if x%2 == 1 else None for x in L ]
[None, 1, None, 3, None, 5, None, 7, None, 9, None]
</code></pre>
| 2 | 2009-10-08T19:57:34Z | [
"python",
"list",
"performance",
"replace"
] |
Replace values in list using Python | 1,540,049 | <p>I have a list where I want to replace values with None where condition() returns True.</p>
<pre><code>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
</code></pre>
<p>For example, if condition checks bool(item%2) should return:</p>
<pre><code>[None, 1, None, 3, None, 5, None, 7, None, 9, None]
</code></pre>
<p>What is the mo... | 59 | 2009-10-08T19:54:18Z | 1,540,069 | <p>The most efficient:</p>
<pre><code>items = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for index, item in enumerate(items):
if not (item % 2):
items[index] = None
</code></pre>
<p>The easiest to read:</p>
<pre><code>new_items = [x if x % 2 else None for x in items]
</code></pre>
| 90 | 2009-10-08T19:58:50Z | [
"python",
"list",
"performance",
"replace"
] |
Replace values in list using Python | 1,540,049 | <p>I have a list where I want to replace values with None where condition() returns True.</p>
<pre><code>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
</code></pre>
<p>For example, if condition checks bool(item%2) should return:</p>
<pre><code>[None, 1, None, 3, None, 5, None, 7, None, 9, None]
</code></pre>
<p>What is the mo... | 59 | 2009-10-08T19:54:18Z | 1,540,071 | <pre><code>ls = [x if (condition) else None for x in ls]
</code></pre>
| 44 | 2009-10-08T19:58:57Z | [
"python",
"list",
"performance",
"replace"
] |
Replace values in list using Python | 1,540,049 | <p>I have a list where I want to replace values with None where condition() returns True.</p>
<pre><code>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
</code></pre>
<p>For example, if condition checks bool(item%2) should return:</p>
<pre><code>[None, 1, None, 3, None, 5, None, 7, None, 9, None]
</code></pre>
<p>What is the mo... | 59 | 2009-10-08T19:54:18Z | 1,541,791 | <p>Riffing on a side question asked by the OP in a comment, i.e.:</p>
<blockquote>
<p>what if I had a generator that yields
the values from range(11) instead of a
list. Would it be possible to replace
values in the generator?</p>
</blockquote>
<p>Sure, it's trivially easy...:</p>
<pre><code>def replaceiniter... | 10 | 2009-10-09T04:29:08Z | [
"python",
"list",
"performance",
"replace"
] |
Replace values in list using Python | 1,540,049 | <p>I have a list where I want to replace values with None where condition() returns True.</p>
<pre><code>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
</code></pre>
<p>For example, if condition checks bool(item%2) should return:</p>
<pre><code>[None, 1, None, 3, None, 5, None, 7, None, 9, None]
</code></pre>
<p>What is the mo... | 59 | 2009-10-08T19:54:18Z | 1,543,104 | <p>Here's another way:</p>
<pre><code>>>> L = range (11)
>>> map(lambda x: x if x%2 else None, L)
[None, 1, None, 3, None, 5, None, 7, None, 9, None]
</code></pre>
| 5 | 2009-10-09T10:54:17Z | [
"python",
"list",
"performance",
"replace"
] |
How to print the function name as a string in Python from inside that function | 1,540,177 | <pre><code>def applejuice(q):
print THE FUNCTION NAME!
</code></pre>
<p>It should result in "applejuice" as a string.</p>
| 6 | 2009-10-08T20:21:45Z | 1,540,189 | <p>You need to explain what your problem is. Because the answer to your question is:</p>
<pre><code>print "applejuice"
</code></pre>
| 3 | 2009-10-08T20:23:38Z | [
"python"
] |
How to print the function name as a string in Python from inside that function | 1,540,177 | <pre><code>def applejuice(q):
print THE FUNCTION NAME!
</code></pre>
<p>It should result in "applejuice" as a string.</p>
| 6 | 2009-10-08T20:21:45Z | 1,540,211 | <pre><code>def applejuice(**args):
print "Running the function 'applejuice'"
pass
</code></pre>
<p>or use:</p>
<pre><code>myfunc.__name__
>>> print applejuice.__name__
'applejuice'
</code></pre>
<p>Also, see <a href="http://stackoverflow.com/questions/251464/how-to-get-the-function-name-as-string-i... | 7 | 2009-10-08T20:27:10Z | [
"python"
] |
How to print the function name as a string in Python from inside that function | 1,540,177 | <pre><code>def applejuice(q):
print THE FUNCTION NAME!
</code></pre>
<p>It should result in "applejuice" as a string.</p>
| 6 | 2009-10-08T20:21:45Z | 1,540,215 | <pre><code>import traceback
def applejuice(q):
stack = traceback.extract_stack()
(filename, line, procname, text) = stack[-1]
print procname
</code></pre>
<p>I assume this is used for debugging, so you might want to look into the other procedures offered by the <a href="http://docs.python.org/library/traceba... | 7 | 2009-10-08T20:28:04Z | [
"python"
] |
How to print the function name as a string in Python from inside that function | 1,540,177 | <pre><code>def applejuice(q):
print THE FUNCTION NAME!
</code></pre>
<p>It should result in "applejuice" as a string.</p>
| 6 | 2009-10-08T20:21:45Z | 1,540,245 | <p>Another way</p>
<pre><code>import inspect
def applejuice(q):
print inspect.getframeinfo(inspect.currentframe())[2]
</code></pre>
| 3 | 2009-10-08T20:31:39Z | [
"python"
] |
How to print the function name as a string in Python from inside that function | 1,540,177 | <pre><code>def applejuice(q):
print THE FUNCTION NAME!
</code></pre>
<p>It should result in "applejuice" as a string.</p>
| 6 | 2009-10-08T20:21:45Z | 1,540,257 | <p>This also works:</p>
<pre><code>import sys
def applejuice(q):
func_name = sys._getframe().f_code.co_name
print func_name
</code></pre>
| 13 | 2009-10-08T20:33:18Z | [
"python"
] |
How to print the function name as a string in Python from inside that function | 1,540,177 | <pre><code>def applejuice(q):
print THE FUNCTION NAME!
</code></pre>
<p>It should result in "applejuice" as a string.</p>
| 6 | 2009-10-08T20:21:45Z | 17,332,402 | <pre><code>def foo():
# a func can just make a call to itself and fetch the name
funcName = foo.__name__
# print it
print 'Internal: {0}'.format(funcName)
# return it
return funcName
# you can fetch the name externally
fooName = foo.__name__
print 'The name of {0} as fetched: {0}'.format(fooNam... | 0 | 2013-06-26T23:59:17Z | [
"python"
] |
How to print the function name as a string in Python from inside that function | 1,540,177 | <pre><code>def applejuice(q):
print THE FUNCTION NAME!
</code></pre>
<p>It should result in "applejuice" as a string.</p>
| 6 | 2009-10-08T20:21:45Z | 29,151,834 | <p>This site gave me a decent explanation of how sys._getframe.f_code.co_name works that returns the function name. </p>
<p><a href="http://code.activestate.com/recipes/66062-determining-current-function-name/" rel="nofollow">http://code.activestate.com/recipes/66062-determining-current-function-name/</a></p>
| 1 | 2015-03-19T17:59:40Z | [
"python"
] |
Why isn't getopt working if sys.argv is passed fully? | 1,540,365 | <p>If I'm using this with <code>getopt</code>:</p>
<pre><code>import getopt
import sys
opts,args = getopt.getopt(sys.argv,"a:bc")
print opts
print args
</code></pre>
<p><code>opts</code> will be empty. No tuples will be created. If however, I'll use <code>sys.argv[1:]</code>, everything works as expected. I don't un... | 4 | 2009-10-08T20:48:48Z | 1,540,392 | <p>It's by design. Recall that sys.argv[0] is the running program name, and getopt doesn't want it.</p>
<p>From the docs:</p>
<blockquote>
<p>Parses command line options and
parameter list. args is the argument
list to be parsed, without the leading
reference to the running program.
Typically, this means sy... | 6 | 2009-10-08T20:51:45Z | [
"python",
"getopt"
] |
Why isn't getopt working if sys.argv is passed fully? | 1,540,365 | <p>If I'm using this with <code>getopt</code>:</p>
<pre><code>import getopt
import sys
opts,args = getopt.getopt(sys.argv,"a:bc")
print opts
print args
</code></pre>
<p><code>opts</code> will be empty. No tuples will be created. If however, I'll use <code>sys.argv[1:]</code>, everything works as expected. I don't un... | 4 | 2009-10-08T20:48:48Z | 1,540,399 | <p>The first element of <code>sys.argv</code> (<code>sys.argv[0]</code>) is the name of the script currently being executed. Because this script name is (likely) not a valid argument (and probably doesn't begin with a <code>-</code> or <code>--</code> anyway), <code>getopt</code> does not recognize it as an argument. D... | 11 | 2009-10-08T20:53:25Z | [
"python",
"getopt"
] |
Recurrence sequence in Java / Python / Mathematica | 1,540,519 | <p><strong>How can you write the following statement in the given languages?</strong></p>
<pre><code>a(0) = 1
a_(n+1) = 1 - 1 / ( a_n + 3)
</code></pre>
<p>I need to find the smallest value of <code>n</code> when <code>a_n -> 0.732050...</code>.</p>
<p><strong>My attempt in Mathematica</strong></p>
<pre><code>a[... | 3 | 2009-10-08T21:12:03Z | 1,540,601 | <p>Java</p>
<pre><code>double A = 1;
int n = 0;
while (true) {
System.out.println(n + " " + A);
A = 1 - 1 / (A + 3);
n++;
}
</code></pre>
<p>Python</p>
<pre><code>A = 1.0
n = 0
while 1:
print n, A
A = 1 - 1 / (A + 3)
n += 1
</code></pre>
| 3 | 2009-10-08T21:27:20Z | [
"java",
"python",
"wolfram-mathematica",
"sequence"
] |
Recurrence sequence in Java / Python / Mathematica | 1,540,519 | <p><strong>How can you write the following statement in the given languages?</strong></p>
<pre><code>a(0) = 1
a_(n+1) = 1 - 1 / ( a_n + 3)
</code></pre>
<p>I need to find the smallest value of <code>n</code> when <code>a_n -> 0.732050...</code>.</p>
<p><strong>My attempt in Mathematica</strong></p>
<pre><code>a[... | 3 | 2009-10-08T21:12:03Z | 1,540,622 | <p>Mathematica:</p>
<pre><code>a[0] := 1
a[k_] := 1 - 1/(a[k - 1] + 3)
</code></pre>
<p>I substituted k = n + 1 because that makes the expression simpler. The result is equivalent.</p>
| 3 | 2009-10-08T21:30:28Z | [
"java",
"python",
"wolfram-mathematica",
"sequence"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.